On Windows, File::getAbsolutePath() will return backward-slashes in paths; on UNIX, forward-slashes.
Since both versions are valid filenames on Windows machine, is it possible to force File::getAbsolutePath() (and associated functions) to always return the forward-slash version of a filename?
You could use a function like replaceAll() to replace any backward-slash in the path by forward-slashes. This would look like :
String oldPath = "path\\dzq\\dzqf";
String newPath = old.replaceAll("\\\\","/");
replaceAll takes a regular expression, which is why not just two backslashes are required in the first parameter. See https://stackoverflow.com/a/5596492.
More info on replaceAll() here : https://www.javatpoint.com/java-string-replaceall and here : https://howtodoinjava.com/java/string/java-string-replaceall-example/
The functions returning you the path always use the platform's default separator : https://www.journaldev.com/851/java-file-separator-separatorchar-pathseparator-pathseparatorchar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With