JAVA获取当前工程路径(非web工程)
import java.io.File;
import javax.xml.parsers.DocumentBuilderFactory;
......
File file = new File("");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
String path = file.getAbsolutePath(); // the project path what you want
注:不适合web工程
--------------------------------------------------------------------------------------------
或者
String path = System.getProperty("user.dir"); // the project path what you want
注: getProperty()方法可以获得系统的各种参数,具体的说明可参见System.getPropertis()文档;
本文介绍两种在非Web环境下获取JAVA工程路径的方法:一是通过创建空File对象并调用getAbsolutePath()方法;二是直接使用System.getProperty(user.dir)来获取。
4684





