(只适用于非WEB工程) File file = new File(""); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); String path = file.getAbsolutePath(); (WEB工程下得到的是tomcat下的路径)