首页 > 在java里,为什么同样一条String,输出到终端和保存到文件的长度不同?

在java里,为什么同样一条String,输出到终端和保存到文件的长度不同?

我需要把一个很复杂的数据结构保存为JSON。

JSONArray jRecords=new JSONArray();
...
...
PrintWriter out = new PrintWriter(
new FileOutputStream(
    Config.resultFolder+File.separator+"record.json"));  
String str=jRecords.toString();
System.out.print(str);
out.print(str);

System.out.print可以正常输出,但是PrinterWriter的结果好像是后面的结果被砍掉了,不完整。是因为缓冲区不够大还是怎么样?


是否忘记了 out.flush() ?

【热门文章】
【热门文章】