欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

jdom解决中文乱码问题 JAVA生成xml文件

程序员文章站 2022-05-28 12:36:17
...

package com.sinosoft.jbs.sevices.sinolifelast.test;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;

import org.jdom.output.XMLOutputter;
public class CreateXML {
	public void create(){
		Element root=new Element("PEOPLE");
		Document doc=new Document(root);
		Element person=new Element("PERSON");
		root.addContent(person);
		Attribute attribute=new Attribute("title","这是一个测试的文字");
		person.addAttribute(attribute);
		XMLOutputter output=new XMLOutputter();
		try {
			//FileWriter writer=new FileWriter("src/people.xml");
			OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream("d:/people.xml"), "UTF-8");
			output.output(doc, writer);
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		new CreateXML().create();
	}
}
 转载之(http://blog.csdn.net/zhq426/article/details/7207496)