我收到错误io.MalformedByteSequenceException:2字节UTF-8序列的无效字节2
解决方案是以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完成读写?