且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Java 应用程序中读取 XML 文件的***/最简单方法是什么?

更新时间:2021-12-16 08:57:53

当然,根据您的需要,有很多好的解决方案.如果只是配置,你应该看看 Jakarta commons-configurationcommons-digester.

There are of course a lot of good solutions based on what you need. If it is just configuration, you should have a look at Jakarta commons-configuration and commons-digester.

您始终可以使用标准的 JDK 方法来获取文档:

You could always use the standard JDK method of getting a document :

import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;

[...]

File file = new File("some/path");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(file);