While I was working on some file operations in java, I came across the File.pathSeparator and found that this returns ";" and where as System.getParameter("file.separator") as "\". I'm using windows system.
No, the path separator and the file separator are not the same thing.
The path separator is used to separate elements on for example the classpath. On Windows, it's ";" and on Unix-like operating systems it's ":".
The file separator is used to separate directory names and filenames on a file path. On Windows, it's "\" and on Unix-like operating systems it's "/".
Note that class File has, besides a variable called pathSeparator, also a variable called separator. That last one is the same as System.getProperty("file.separator"). Also, there is also a system property called "path.separator", which is, ofcourse, the path separator.
Darryl Burke wrote:On at least the last three Windows versions, both \ and / are accepted. Not just from a Java program, but even in the Command Prompt window.
That's mostly true but there are a few exceptions. For example the command-line "ftp" program still requires \ as its path separator. However it doesn't handle file names containing the _ character properly so it can hardly be held up as a good example.
subject: Differences between System.getProperty("file.seperator") and File.pathSeparator