用java做播放器
读和写xml文件,发现写完后xml文件的中文就变成了乱码,
查了好久终于解决了
环境:字符过滤器用的是gb2312,xml文件的头部编码是gb2312,java写入xml文件用到的StreamResult编码方式是gb2312
解决办法:把xml文件的头部编码改为utf-8,StreamResult编码方式也改为utf-8
xml头:
<?xml version="1.0" encoding="utf-8"?>
java部分代码:
try {
fos = new FileOutputStream(FileName);
osw = new OutputStreamWriter(fos);
((XmlDocument) doc).write(osw, "utf-8");
osw.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}