用jdom解析xml文件时如何解决中文问题?如何解析?

用jdom解析xml文件时如何解决中文问题?如何解析?

package com.usernet.test;

import java.io.*;

public class Test13 {
 private String inFile = "F://people.xml";
 private String outFile = "F://people.xml";

 public static void main(String args[]) {
  new Test13();
 }

 public Test13() {
  try {
   javax.xml.parsers.DocumentBuilder builder =

   javax.xml.parsers.DocumentBuilderFactory.newInstance()
     .newDocumentBuilder();
   org.w3c.dom.Document doc = builder.newDocument();
   org.w3c.dom.Element root = doc.createElement("老师");
   org.w3c.dom.Element wang = doc.createElement("王");
   wang.appendChild(doc.createTextNode("我是王老师"));
   org.w3c.dom.Element liu = doc.createElement("刘");
   liu.appendChild(doc.createTextNode("liu老师!"));
   root.appendChild(wang);
   root.appendChild(liu);
   doc.appendChild(root);
   javax.xml.transform.Transformer transformer = javax.xml.transform.TransformerFactory
     .newInstance().newTransformer();
   transformer.setOutputProperty(
     javax.xml.transform.OutputKeys.ENCODING, "gb2312");
   transformer.setOutputProperty(
     javax.xml.transform.OutputKeys.INDENT, "yes");

   transformer.transform(new javax.xml.transform.dom.DOMSource(doc),
     new javax.xml.transform.stream.StreamResult(outFile));
  } catch (Exception e) {
   System.out.println(e.getMessage());
  }
 }
}

你可能感兴趣的:(用jdom解析xml文件时如何解决中文问题?如何解析?)