There is an example code:
private void analyzeCurve() throws IOException { if (listX.isEmpty() || listY.isEmpty()) { WorkspaceWindow.showWarningMessage(EMPTY_DRAWING_LIST); } else { ArrayList<Integer> lx; ArrayList<Integer> ly; File xmlFile = new File(File.separator + "tmp" + File.separator + "xmlFile.xml"); //создание файла FileWriter fr = new FileWriter(xmlFile); BufferedWriter writer = new BufferedWriter(fr); //действия с файлом... writer.flush(); writer.close(); } } When running under Linux, the file is successfully created and written to. But during the launch of the code in Windows file is not created.
We get an exception:
java.io.FileNotFoundException: \tmp\xmlFile (Системе не удается найти указанный путь) at java.io.FileOutputStream.open0(Native Method) at java.io.FileOutputStream.open(FileOutputStream.java:270) at java.io.FileOutputStream.<init>(FileOutputStream.java:213) at java.io.FileOutputStream.<init>(FileOutputStream.java:162) at java.io.FileWriter.<init>(FileWriter.java:90) at client.logic.Analyzer.analyzeCurve(Analyzer.java:69) at client.logic.Analyzer.run(Analyzer.java:43) This is due, as I understand it, to the absence of the \ tmp \ directory in Windows, but then the question arises:
1. How to create files in Windows and Linux in the tmp folder, that is, in the folder for temporary files?
2. Is it possible to somehow understand what system we are in and, depending on this, set the path for creating files?