繁体   English   中英

读取xml(Windows-1252)文件时出错

[英]Error while reading a xml (windows-1252) file

我已经用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);
    }
}

您正在使用默认字符集读取文件。 如果要读取Windows-1252编码的文件,则需要指定该编码。 您可以使用Charset.forName("windows-1252")来完成此操作,更新后的行应类似于:

 content = Files.readString(Paths.get(path), Charset.forName("windows-1252"));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM