使用wsdl4j从网上读取文件,并将结果写入文件时遇到中文乱码问题,可将
StreamResult result = new StreamResult(file);
改为
FileOutputStream fos;
try {
fos = new FileOutputStream(file,true);
Writer out = new OutputStreamWriter(fos, "UTF8");
StreamResult result = new StreamResult(out);
transformer.transform(sourceContent, result);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
使用OutputStreamWriter指定编码,因为默认是系统当前编码。
StreamResult result = new StreamResult(file);
改为
FileOutputStream fos;
try {
fos = new FileOutputStream(file,true);
Writer out = new OutputStreamWriter(fos, "UTF8");
StreamResult result = new StreamResult(out);
transformer.transform(sourceContent, result);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
使用OutputStreamWriter指定编码,因为默认是系统当前编码。