簡體   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