写入文件java时自动添加空间

时间:2017-12-21 18:24:51

标签: java netbeans io filewriter writefile

我有一个函数可以将一些数据写入文件。

{ 
    Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("E:\\Code\\ParseTool\\src\\ketqua.txt"), "Unicode"));

    System.out.print("{\"q\":\"" + ques + "\",\"a\":\"" + ans + "\"},");

    out.write("{\"q\":\"" + ques + "\",\"a\":\"" + ans + "\"},\n"); 
}

当我写入控制台时:数据看起来正确:

{"q":" ��Which of the following methods is defined by the JSP engi....

enter image description here

但是当在txt文件中写入的数据是自动添加空格字符

{"q":" ��W h i c h o f t h e f o l l o w i n g m e t h o d s i s d e f i n e d b y t h e J S P e n g i n e ? ","a":" A n s w e r :

enter image description here

有人帮忙......

0 个答案:

没有答案