目录

JAVA获取当前工程路径非web工程

目录

JAVA获取当前工程路径(非web工程)

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()文档;