-1

从java中获取一个字符串并将其放入一个文本文件中。当字符串被写入时,它不包含 Â,但是当字符串在 word pad 中打开时,字符就会出现。

没有的字符串:

 Notice of Appeal:

 
 Hamilton City Board of Education

字符串:

 Notice of Appeal:
  
  
 Hamilton City Board of Education

下面是写字符串

out = new BufferedWriter (new FileWriter(filePrefix + "-body" + ".txt"));
                    out.write("From:        " + em.from);
                    out.newLine();
                    out.write("Sent Date:   " + em.sentDate);
                    out.newLine();
                    out.write("Subject:     " + em.subject);
                    out.newLine();
                    out.newLine();
                    out.newLine();
                    String temp = new String(emi.stringContent.getBytes("UTF-8"), "UTF-8");
                    out.write(temp);

我应该怎么做才能不让它们出现在 word pad 中?

4

2 回答 2

1

对我来说,这看起来像是一个 UTF-8 编码问题。我相信你得到了这个Â字符,因为你正在用 UTF-8 编写内容,并且内容包含一个高 ASCII 值,但是写字板期望数据在你的本地系统正在运行的代码页中。要么写写字板期望的代码页中的内容,或者使写字板期望 UTF-8。

作为旁白:

String temp = new String(emi.stringContent.getBytes("UTF-8"), "UTF-8");
out.write(temp);

完全是浪费时间;利用:

out.write(emi.stringContent);

反而。

于 2013-05-10T01:39:54.460 回答
0

我假设这是一个行分隔符问题。利用:

String line = System.getProperty("line.separator");

只需将它添加到您想要换行的任何地方

于 2013-05-10T01:20:17.130 回答