// 第一種:獲取類加載的根路徑 //返回的路徑:E:/Tomcat/apache-tomcat-6.0.35/webapps/xasj/WEB-INF/classes File f = new File(this.getClass().getResource("/").getPath()); System.out.PRintln(f);//第二種 獲取當前文件所在的包目錄/*E:/Tomcat/apache-tomcat-6.0.35/webapps/xasj/WEB-INF/classes/com/jeecms/cms/action/directive*/ File f2 = new File(this.getClass().getResource("").getPath()); System.out.println(f2); 1. 配置文件的加載 //獲取 配置文件 jdbc.properties的jdbc.url字段的值String path = getClass().getClassLoader().getResource("/").getPath();+"../config/jdbc.properties";Properties p = new Properties();InputStream in = new FileInputStream(path);p.load(in);String url = p.getProperty("jdbc.url");