SAXエラー– MalformedByteSequenceException:1バイトUTF-8シーケンスのバイト1が無効です。
問題
XMLファイル内の特別なUTF-8文字と、SAXのパーサーがUTF-8を適切に解析するように設定されていない場合、次の例外がスローされます。
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence. ...
溶液
ソリューションは非常に簡単で、コンテンツをUTF-8形式で取得し、SAX入力ソースをオーバーライドします。
File file = new File("c:\\file-utf.xml"); InputStream inputStream= new FileInputStream(file); Reader reader = new InputStreamReader(inputStream,"UTF-8"); InputSource is = new InputSource(reader); is.setEncoding("UTF-8"); saxParser.parse(is, handler);
ここで完全な例を読むことができます–how do read UTF-8 XML file with SAX parser