Java File Path Windows/Linux [closed] Java File Path Windows/Linux [closed] sqlite sqlite

Java File Path Windows/Linux [closed]


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);


You can use slash character as file separator for both OS, in other words you can use C:/PDFMalwareDataAnalyser/Txt/ instead of C:\\PDFMalwareDataAnalyser\\Txt\\ it will still work on Windows OS.


Use System.getProperty("os.name") for obtaining os name, depends on it set path to resource:

String resourcePath = null; switch (System.getProperty("os.name")) {            case "Linux":  resourcePath = "/home/romankooo/work/txt/";                     break;            case "Windows":  resourcePath = "C:\\PDFMalwareDataAnalyser\\Txt\\";                     break;}