Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Platform independent paths in Java

I know the relative path of a file and want to handle it as a File object on both Linux and Windows.

What is the best way to specify platform-independent paths in Java?

like image 961
jakewins Avatar asked Aug 23 '10 14:08

jakewins


People also ask

What is path separator in Java?

pathSeparator: Platform dependent variable for path-separator. For example PATH or CLASSPATH variable list of paths separated by ':' in Unix systems and ';' in Windows system. File. pathSeparatorChar: Same as pathSeparator but it's char.

What is a path delimiter?

The path separator is a character commonly used by the operating system to separate individual paths in a list of paths.

What is the use of file separator in Java?

A file separator is a character that is used to separate directory names that make up a path to a particular location. This character is operating system specific.

How do I set the path of a Unix file in Java?

1) Simple and easy way If Java or Javac is not in your path then you can add them into path by adding "bin" directory or your JDK installation directory into environment variable "PATH". Both windows and UNIX use same name.


1 Answers

Just use /. I've been using it for 23.5 years. Never a problem.

like image 64
user207421 Avatar answered Sep 22 '22 15:09

user207421