[问题] 使用jdom2生成xml时碰到了个小问题

楼主: iamnotgm (伽藍之黑)   2016-04-26 00:35:46
As title
稍微google了一下各种jdom的范例
发现无例外的都会有
<?xml version="1.0" encoding="utf-8" ?>
这样的讯息
但是我怎么写这东西都出不来
我本来以为可以用Format.setOmitDeclaration(false)
但是好像没有用
code大概长这样:
Document xml = new Document();
Format format = Format.getPrettyForm();
// 塞child
BufferedWriter buf = new BufferedWriter(new FileWriter("out.xml"));
format.setOmitDeclaration(false);
format.setOmitEncoding(false);
XMLOutputter xmlout = new XMLOutputter(format);
xmlout.output(xml, buf);
前后当然还有其他东西不过我想不重要
所以是否有其他能确实印出这段编码讯息?
或者我的jdom可能少了什么东西导致他的行为异常?
jdom的版本是2.0.6
java的版本应该是8
感谢各位

Links booklink

Contact Us: admin [ a t ] ucptt.com