I am trying to write a Json String into a File, using FileWriter.
Apparently nothing happens when executing the code.
The Path to my directory is correct.
I also tried different options like Files.writeString(), but it didnt work.
I recreated an example, where I have the same problem like in my actual code:
FileWriter fw = new FileWriter("C:\\User\\lulac\\IdeaProjects\\OOS_Praktikum\\JsonFiles\\test.json");
String content ="[\n" +
" {\n" +
" \"CLASSNAME\": \"OUTGOINGTRANSFER\",\n" +
" \"INSTANCE\": {\n" +
" \"sender\": \"Nico\",\n" +
" \"recipient\": \"Angelo\",\n" +
" \"date\": \"12.01.2020\",\n" +
" \"amount\": 150.0,\n" +
" \"description\": \"Strafzahlung\"\n" +
" }\n" +
" }\n" +
"]\n";
fw.write(content);
fw.close();
Happy about your help
>Solution :
It is a typical German error: it must be Users not User (in German the plural of words ending in "er" remain the same). However: FileWriter is the incorrect class; it will write in the local Windows encoding, and JSON uses UTF-8.
As this is home work: use Files.writeString which uses UTF-8 by default.