I need to implement portable code, but I do not know how to deal with different path conventions on different operating systems.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Ok. Using the File class, if you pass the a given path like so:
new File("myPathInUnixOrWindows");You will get a system independent file path. Make sure you import:
import java.io.File;if you just want the abstract base of the path pass it an empty string:
new File("");http://docs.oracle.com/javase/6/docs/api/java/io/File.html
http://docs.oracle.com/javase/6/docs/api/java/io/File.html#File%28java.lang.String%29