Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

file separators  RSS feed

 
shankar vembu
Ranch Hand
Posts: 309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am aware of using File.separator to specify system independent paths. But I was wondering, if that is really required. For example I read files in my windows machine using "/" as separator and it works. I use only relative path names. These paths should also work on Unix machines as "/" is the path separator there anyways. So do I really need to change all those "/" to File.separator in my code. In my opinion, unless you are using absolute path names in your code,you should not face any problem in using "/" thoughout your code.Right? or Am i missing something here??? BTW I use JDK1.4
Shankar.
 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The goal of Java is to be platform independent, so to that goal they've made platform-specific information available via the system properties. Though you've tested two platforms with "/" it doesn't mean it will work on ALL platforms. I can't think of one that doesn't recognize the "/" file seperator. I guess it boils down to the requirements of your program. Do you intend to deploy on Windows and Unix? Go ahead and use "/". Do you want to be VERY platform-independent? Use file.seperator.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the old days, Macs used ":" as a path separator, and "/" would not be recognized if you used it when calling the Macintosh Toolbox APIs. I don't recall if early Mac JDKs (who else remembers the truly dreadful Macintosh port of JDK 1.0.2?) would let you use "/", but I doubt it -- it's Windows itself that accepts either "\" or "/" (you can use "/" when calling Win32 functions from any language.)
Now, with Mac OS X, I assume "/" is OK, but again, I'm not sure.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!