How to solve Chinese problems when using JDOM to resolve the Chinese problem? How to resolve?
A: Look at the following code, solve the encoding method
Package test;
Import java.io. *;
Public Class Domtest
{
Private string infile = "c: //people.xml";
Private string outfile = "c: //people.xml";
Public static void main (string args [])
{
New domtest ();
}
Public domtest ()
{
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 ("teacher");
Org.w3c.dom.Element Wang = Doc.createElement ("King");
Org.w3c.dom.Element Liu = Doc.createElement ("Liu");
Wang.Appendchild (Doc.createTextNode ("I am Teacher"))
Root.appendchild (wang);
Doc.Appendchild (root);
Javax.xml.transform.transformer Transformer =
Javax.xml.transform.transformerfactory.newinstance (). NewTransformer ();
TRANSFORMER.SETOUTPUTPROPERTY (javax.xml.transform.outputkeys.encoding, "gb2312");
Transformer.setputProperty (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 ());
}
}
}