Java中获取程序路径
package test; public class getDir { public static void main(String[] args) { //包路径:E:\Java EE\myeclipse\Test1 System.out.println(System.getProperty("user.dir")); getDir2 gd=new getDir2(); gd.function(); } } class getDir2{ void function(){ //类路径:/E:/Java%20EE/myeclipse/Test1/bin/test/ System.out.println(this.getClass().getResource("").getPath()); } }