Reputation: 73
I need to write formatted Strings into a .json File without using the JSON library. If I try to use the following code to write a test string I don't get a result inside the .json-File.
FileWriter file = new FileWriter("C:\\Test.json");`
file.write("test");
Upvotes: 0
Views: 452
Reputation: 151
{ "glossary": { "title": "example glossary", "GlossDiv": { "title": "S", "GlossList": { "GlossEntry": { "ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986", "GlossDef": { "para": "A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": ["GML", "XML"] }, "GlossSee": "markup" } } } } }
You have key-value pairs there. Then you use Brackets to define the structure.
Explanation: When you are writing to a file, Java does not want to send each letter to it individually. Therefore it stores them until an certain point is reached if you dont reach that point it wont send the data to the file. To force it, to send the Data use the flush()-Method.
Upvotes: 1