I read several property files to compare them with a template file for missing keys.
FileInputStream compareFis = new FileInputStream(compareFile); Properties compareProperties = new Properties(); compareProperties.load(compareFis);
Note. I am reading a template file in the same way.
After reading, I compare them and write the missing keys with my values โโfrom the template file in Set.
CompareResult result = new CompareResult(Main.resultDir); [...] if (!compareProperties.containsKey(key)) { retVal = true; result.add(compareFile.getName(), key + "=" + entry.getValue()); }
Finally, I write the missing keys and their values โโto a new file.
for (Entry<String, SortedSet<String>> entry : resultSet) { PrintWriter out = null; try { out = new java.io.PrintWriter(resultFile); SortedSet<String> values = entry.getValue(); for (String string : values) { out.println(string); } } catch (FileNotFoundException e) { e.printStackTrace(); } finally { out.flush(); out.close(); } }
If I open the result file, I see that all line breaks "\ n" from the values โโof the template file are replaced with a new line. Example:
test.key=Hello\nWorld!
becomes
test.key=Hello World!
Although this is mostly correct, but in my case I have to save "\ n".
Does anyone know how I can avoid this?
source share