aspose file tools*
The moose likes Beginning Java and the fly likes Differences between System.getProperty( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Differences between System.getProperty("file.seperator") and File.pathSeparator" Watch "Differences between System.getProperty("file.seperator") and File.pathSeparator" New topic
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14156
    
  19

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: 4546
    
    5

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: 18570
    
    8

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Differences between System.getProperty("file.seperator") and File.pathSeparator