所以我试图让我的程序输出一个带有名单列表的文本文件.有些名字有奇怪的字符,例如Åström.
我已经从以“UTF-8”编码的网页中抓取了这些名称列表,或者至少我很确定它的确如此,因为页面来源说
” meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ / “
这是我到目前为止所尝试的:
public static void write(List list) throws IOException {
Writer out = new OutputStreamWriter(new FileOutputStream("test.txt"), "UTF-8");
try {
for (int i=0;i
try {
byte[] utf8Bytes = list.get(i).getBytes("UTF-8");
out.write(new String(utf8Bytes, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
out.write(System.getProperty("line.separator"));
}
}
finally {
out.close();
}
}
我有点困惑为什么它不起作用.我得到的输出是“Ã…ström”,这非常奇怪.
有人可以指出我正确的方向吗?谢谢!
在另一个不相关的说明中,除了笨重之外,是否有更简单的方法将新行写入文本文件
out.write(System.getProperty(“line.separator”));
我有?我在某个地方看到了网络并且它可以工作,但我只是想知道是否有更清洁的方式.