让我解释一下。我有一个字符串是JoaquÃnTorresGarcÃa然后当我使用上面的代码解析它时,生成的txt文件具有Joa ????形式的相同名称Torres Garc ???? a。我正在使用以下代码将以这种方式组成的字符串写入文本文件:
java.util.Iterator<String> itr = set.iterator();
int occur = 0;
File w = new File("newnodes.txt");
try (BufferedWriter wr = new BufferedWriter(new FileWriter(w))) {
//String def = "nodedef>name VARCHAR,label VARCHAR";
//wr.write(def);
wr.newLine();
while (itr.hasNext()) {
occur++;
String str = (String.valueOf(occur))+","+ (itr.next());
wr.write(str);
wr.newLine();
}
System.out.println("Node file Created");
答案 0 :(得分:2)
使用UTF-8 Writer
File w = new File("newnodes.txt");
try (Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(w), "UTF-8"))) {
//stuff here..