What is the difference between using File.separator
and a normal /
in a Java Path-String?
In contrast to double backslash \\\\
If you are trying to create a File from some ready path (saved in database, per example) using Linux separator, what should I do?
Maybe just use the path do create the file:
new File("/shared/folder/file.jpg");
But Windows use a different separator (\
). So, is the alternative convert the slash separator to platform independent? Like:
new File(convertPathToPlatformIndependent("/shared/folder"));
This method convertPathToPlatformIndependent
probably will have some kind of split by "/" and join with File.separator.
Well, for me, that's not nice for a language that is platform independent (right?) and Java already support the use of /
on Windows or Linux. But if you are working with paths and need to remember to this conversion every single time this will be a nightmare and you won't have any real gain for the application on the future (maybe in the universe that @Pointy described).