标签:enc system set stream puts creat sys fill style
public static void writToXml(Document document) throws IOException { OutputFormat format=OutputFormat.createPrettyPrint(); XMLWriter writer=new XMLWriter(new FileOutputStream(fillpath),format); writer.write(document);//写入文件 format=OutputFormat.createPrettyPrint(); writer=new XMLWriter(System.out,format);//输出到屏幕 writer.write(document); }
第二段代码在输出屏幕的时候,输出中文是乱码的。
修改如下后即输出中文了:
public static void writToXml(Document document) throws IOException { OutputFormat format=OutputFormat.createPrettyPrint(); XMLWriter writer=new XMLWriter(new FileOutputStream(fillpath),format); writer.write(document); format=OutputFormat.createPrettyPrint(); format.setEncoding("gb2312"); writer=new XMLWriter(System.out,format); writer.write(document); }
标签:enc system set stream puts creat sys fill style
原文地址:https://www.cnblogs.com/alsf/p/9279519.html