第一种: File f = new File(this.getClass().getResource("/").getPath()); System.out.println(f); 结果: C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin 获取当前类的所在工程路径; 如果不加“/” File f = new File(this.getClass().getResource(""
public class PathTest { public static void main(String[] args) { //获取根路径三种方式 System.out.println(PathTest.class.getClassLoader().getResource("")); System.out.println(ClassLoader.getSystemClassLoader().getResource("")); System.out.printl