我用java编写了一个应该读取xml文件的程序,但在使用windows-1252读取xml文件时出错:
java.nio.charset.MalformedInputException:输入长度=3
但UTF-8为我工作。
public class InputBox {
public static void XmlOeffnen() throws IOException {
JFileChooser chooser = new JFileChooser();
int rueckgabeWert = chooser.showOpenDialog(null);
String content = null;
File f = chooser.getSelectedFile();
String path = f.getAbsolutePath();
try {
content = Files.readString(Paths.get(path), Charset.defaultCharset());
} catch (IOException e) {
e.printStackTrace();
}
Converter.Konvertieren(chooser.getName(), content, path);
}
}发布于 2019-08-05 08:46:25
您正在使用默认字符集读取文件。如果要读取使用Windows1252编码的文件,则需要指定该编码。您可以使用Charset.forName("windows-1252")完成此操作,更新后的行应该如下所示:
content = Files.readString(Paths.get(path), Charset.forName("windows-1252"));https://stackoverflow.com/questions/57354888
复制相似问题