import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.output.XMLOutputter;
public class JDOMXMLWriteDemo {
public static void main(String[] args) {
Element rss = new Element("rss");
rss.setAttribute("version", "2.0");
Document document = new Document(rss);
Element channel = new Element("channel");
channel.setText("<大家好>");
rss.addContent(channel);
XMLOutputter outputer = new XMLOutputter();
try {
outputer.output(document, new FileOutputStream(new File("news.xml")));
} catch (FileNotFoundException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
可能你的classpath设置有问题,当前路径并不在classpath配置中,在classpath中添加“.”表示当前目录