jdom出來xml文件比較方便,尤其是在讀寫文件的時候,但出xml文件的時候,要format一下,這樣看起來比較方便,因項目需要和別的公司做接口,傳輸就采用xml文件,起初寫xml文件時候沒格式化,不過輸出實在不好看.今天晚上就寫了個程序格式化,發上來大家一起學習.

????public?void?writeFormatXML(Document?doc,?String?filename)?
{
????????String?indent?=?"????";?//?縮進符號
????????boolean?newLines?=?true;?//?是否產生新行
????????XMLOutputter?outp?=?new?XMLOutputter(indent,?newLines,?"gb2312");?//?構造新的輸出流

????????try?
{
????????????outp.output(doc,?new?FileOutputStream(filename));

????????}?catch?(FileNotFoundException?e)?
{
????????????e.printStackTrace();

????????}?catch?(IOException?e)?
{
????????????e.printStackTrace();
????????}
????}