I'm writing to a file using PrintWriter like this:
Gson g = new Gson();
Article article = g.fromJson(reader, Article.class);
String json = g.toJson(article);
PrintWriter out = new PrintWriter(new FileWriter(cacheFile.getAbsolutePath()));
out.print(json);
However, the string in json is truncated when I see it in the file. What could be the reason for that?
You need to close the PrintWriter using PrintWriter#close() method
Add
out.close();
It doesn't. You failed to close the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With