When should I use File.separator and when File.pathSeparator?

icnhzabot picture icnhzabot · May 12, 2011 · Viewed 413.2k times · Source

In the File class there are two strings, separator and pathSeparator.

What's the difference? When should I use one over the other?

Answer

user489041 picture user489041 · May 12, 2011

If you mean File.separator and File.pathSeparator then:

  • File.pathSeparator is used to separate individual file paths in a list of file paths. Consider on windows, the PATH environment variable. You use a ; to separate the file paths so on Windows File.pathSeparator would be ;.

  • File.separator is either / or \ that is used to split up the path to a specific file. For example on Windows it is \ or C:\Documents\Test