Created
October 17, 2023 21:18
-
-
Save ov7a/c971dfe516f1beb11db847faea44ca57 to your computer and use it in GitHub Desktop.
Java folder creating utf inconsistency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.io.File; | |
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.util.concurrent.Callable; | |
import java.util.function.Consumer; | |
import java.util.function.Function; | |
public class App { | |
@FunctionalInterface | |
public interface Action { | |
void apply(Path path) throws IOException; | |
} | |
public static void main(String[] args) throws IOException { | |
check("createDirectory", Files::createDirectory); | |
check("mkdir", x -> x.toFile().mkdir()); | |
} | |
private static void check(String hint, Action createDir) throws IOException { | |
String name = "teŝt files"; | |
Path root = Path.of(name).toAbsolutePath(); | |
Path file = root.resolve("file1"); | |
Files.deleteIfExists(file); | |
Files.deleteIfExists(root); | |
createDir.apply(root); | |
Files.createFile(file); | |
Path alternative = file.toRealPath(); | |
System.out.printf("%s - Equals: %s, isSameFile: %s\n", hint, file.equals(alternative), Files.isSameFile(file, alternative)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
createDirectory - Equals: true, isSameFile: true | |
mkdir - Equals: false, isSameFile: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment