Here you can find the source of getDocument(File file)
static public Document getDocument(File file) throws IOException, ParserConfigurationException, SAXException
//package com.java2s; //License from project: Apache License import org.w3c.dom.Document; import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; public class Main { static public Document getDocument(File file) throws IOException, ParserConfigurationException, SAXException { InputStream stream = new FileInputStream(file); return getDocument(stream); }/*from w w w . ja va 2 s .c o m*/ static public Document getDocument(Path filePath) throws IOException, ParserConfigurationException, SAXException { return getDocument(filePath.toFile()); } static public Document getDocument(InputStream stream) throws IOException, SAXException, ParserConfigurationException { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(stream); doc.getDocumentElement().normalize(); return doc; } }