I am writing a class for creating / reading properties files. Each file is in its own folder. It is necessary to implement getting the path to start the program and collect the path Everything is good except for one when passing the path to FileWriter gives an error (Syntax error in the file name, folder name or volume label). How to overcome Here is the compiled file:\E:\Project Java\Project Idea\esteamerbase\out\artifacts\web_ee_war_exploded\WEB-INF\classes\CashBack\cashback_config.properties error with it. If you stick the Filewriter constructor directly this way, everything works.

The code that I use

 public void setListSumProperties(List<SumProperties> listSumProperies)throws IOException{ String path = "/CashBack/cashback_config.properties";//Папка с config path = URLDecoder.decode(getClass().getResource(path).toString(),"utf-8");//Преобразованный путь без %20 System.out.println(path); FileWriter fileWriter = new FileWriter(path); for (SumProperties sum:listSumProperies ) { fileWriter.write(sum.getProcent()+"="+sum.getProcent_value()+System.getProperty("line.separator")); fileWriter.write(sum.getSum()+"="+sum.getSum_value()+System.getProperty("line.separator")); } fileWriter.close(); } 

Thank you in advance

    1 answer 1

     Properties prop = new Properties(); OutputStream output = null; try { output = new FileOutputStream("config.properties"); // set the properties value prop.setProperty("database", "localhost"); prop.setProperty("dbuser", "mkyong"); prop.setProperty("dbpassword", "password"); // save properties to project root folder prop.store(output, null); } catch (IOException io) { io.printStackTrace(); } finally { if (output != null) { try { output.close(); } catch (IOException e) { e.printStackTrace(); } } } 
    • Comments are not intended for extended discussion; conversation moved to chat . - Yuriy SPb