Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java File Path Windows/Linux [closed]

what is the best solution to create file path in Java for this two OS. Application will be used for this os , the i need to create universal String.

for example : For Linux:

public File folderTxt = new File("/home/romankooo/work/txt/");

For Windows:

public File folderTxt = new File("C:\\PDFMalwareDataAnalyser\\Txt\\");

Or is the best solution to generate 2 .jar files for this OS.

Thank a lot guys.

like image 752
bilinxe Avatar asked Apr 16 '16 10:04

bilinxe


1 Answers

The best thing is to let java decide that for you like this

    public File folderTxt = new File(File.separator + "home" + File.separator + "romankooo" + File.separator + "work" + File.separator + "txt" + File.separator);
like image 50
microtone Avatar answered Sep 23 '22 11:09

microtone