xml默认的encoding1般都是utf8编码格式

解决方案 »

  1.   

    dom4j中可以设置XMLr的Format信息,可以设置xml文件的编码格式/输出格式。
      

  2.   

    try{
         SAXReader saxReader = new SAXReader();    
         Document document = saxReader.read(new File("c:\\myxml.xml"));
         XMLWriter output = null;
         /** 格式化xml输出 */
         OutputFormat format = OutputFormat.createPrettyPrint();
         format.setEncoding("GBK");//字符集
         output = new XMLWriter(new FileWriter(new File(filename)),format);
         output.write(document);
         output.close();        
    }catch(Exception ex){
         ex.printStackTrace();
    }