• Post Reply Bookmark Topic Watch Topic
  • New Topic

unch path - path compatibility on windows & solaris  RSS feed

 
manish ahuja
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
I dont know if this possible . some one told me that its possible with unc path.
I want to create an IO program say reading or writing to directory (windows & solaris)
but i dont wnat 2 keep changing the code depending on the OS on which the OS program will run
can we use UNC path to acheive to have a common path
what i want to ensure is the program runs without any change if it is run on windows or solaris
can we have a path (written in such a way) which can work both on windows & solaris
Bye
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forget about UNC path. It's a Microsoft standard; irrelevant on Unix.
There are various ways in Java to work with paths in a platform-neutral manner. The basic rule of thumb is, never put a "/" or "\\" in your code when talking about a path. That means you're constructing a path which is specific to MS or Unix. (Dunno how Macs fit in here.) Generally if you want to create a path, you can use the File class to create it. E.g.

or

or

If you need to get user input identifying a path to use, JFileChooser is a good way to do this graphically. The user just points and clicks, and it will give you a path in the correct format for your machine.

For more complex operations, you may want to look at JNDI, which is included in the JDK under the javax.naming packages.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!