我收到一个错误io.MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence
解决方案是以 UTF-8 读写文件。
我的代码是:
InputStream input = null;
OutputStream output = null;
OutputStreamWriter bufferedWriter = new OutputStreamWriter( output, "UTF8");
input = new URL(url).openStream();
output = new FileOutputStream("DirectionResponse.xml");
byte[] buffer = new byte[1024];
for (int length = 0; (length = input.read(buffer)) > 0;) {
output.write(buffer, 0, length);
}
BufferedReader br = new BufferedReader(new FileReader("DirectionResponse.xml" ));
FileWriter fstream = new FileWriter("ppre_DirectionResponse.xml");
BufferedWriter out = new BufferedWriter(fstream);
我正在读取一个 url 并将其写入文件DirectionResponse.xml。然后读取DirectionResponse.xml并写入与 *ppre_DirecionResponse.xml* 相同的内容进行处理。
如何更改它以便以 UTF-8 进行读写?