Can someone explain what I'm doing wrong and/or missing here. I have java.nio.file.Path objects that work fine in my Java application. The only issue is when I try to print them out in logs, and the issue is only present on Windows. When I stringify a Path object (or File object), I get some path like build/somefile.txt on Linux, Unix, Mac, but on Windows it prints as buildsomefile.txt. What I would expect to see is build\\somefile.txt, but instead, the slashes are ommitted on Windows.
This is the simple example code that I've executed on Mac, Ubuntu, and Windows with Java 11 and Java 17:
import java.nio.file.Paths;
System.out.println(Paths.get("build", "somefile.txt"));
System.out.println(Paths.get("build", "somefile.txt").toFile());
System.out.println(Paths.get("build", "somefile.txt").toFile().getPath());
Same behavior if I normalize the path, convert to an absolute path, etc. From the docs of Path, it looks to me like toString() should use File.separator here, which is the behavior I do see on non-Windows systems. The docs also do specify that the Windows separatorChar is \\. Can anyone help me understand what I'm missing here? Thanks!
EDIT:
These all also output empty strings:
import java.nio.file.File;
System.out.println(File.separator);
System.out.println(File.separatorChar);
It's worth noting I'm seeing this in tests, if that is relevent.