[問題] 使用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