Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

like image 323
icnhzabot Avatar asked May 12 '11 00:05

icnhzabot


People also ask

What is the use of file separator?

The file separator is the character used to separate the directory names that make up the path to a specific location.

What is file path separator?

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.

Why do we use separator in Java?

A file separator is a character that is used to separate directory names that make up a path to a particular location. This character is operating system specific.

What is path separator in Java?

pathSeparator: Platform dependent variable for path-separator. For example PATH or CLASSPATH variable list of paths separated by ':' in Unix systems and ';' in Windows system. File. pathSeparatorChar: Same as pathSeparator but it's char.


1 Answers

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

like image 188
user489041 Avatar answered Oct 19 '22 03:10

user489041