Skip to content

Instantly share code, notes, and snippets.

@ov7a
Created October 17, 2023 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ov7a/c971dfe516f1beb11db847faea44ca57 to your computer and use it in GitHub Desktop.
Save ov7a/c971dfe516f1beb11db847faea44ca57 to your computer and use it in GitHub Desktop.
Java folder creating utf inconsistency
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));
}
}
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