| Author |
Differences between System.getProperty("file.seperator") and File.pathSeparator
|
Rajani Gummadi
Ranch Hand
Joined: Dec 17, 2010
Posts: 48
|
|
Hello All,
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.
Don't these two should denote the same ?
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12953
|
|
Welcome to JavaRanch.
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.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Rajani Gummadi
Ranch Hand
Joined: Dec 17, 2010
Posts: 48
|
|
|
Thanks Jesper for clarifying and also for providing additional guidance.
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4203
|
|
On Windows, it's "\" and on Unix-like operating systems it's "/".
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.
|
luck, db
There are no new questions, but there may be new answers.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
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
|
|
|