File f = new File(this.getClass().getResource("").getPath());
System.out.println(f);ç»æï¼C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin\com\test
è·åå½åç±»çç»å¯¹è·¯å¾ï¼ç¬¬äºç§ï¼File directory = new File("");//åæ°ä¸ºç©º
String courseFile = directory.getCanonicalPath() ;
System.out.println(courseFile);ç»æï¼C:\Documents and Settings\Administrator\workspace\projectName
è·åå½åç±»çæå¨å·¥ç¨è·¯å¾;第ä¸ç§ï¼URL xmlpath = this.getClass().getClassLoader().getResource("selected.txt");
System.out.println(xmlpath);ç»æï¼file:/C:/Documents%20and%20Settings/Administrator/workspace/projectName/bin/selected.txt
è·åå½åå·¥ç¨srcç®å½ä¸selected.txtæ件çè·¯å¾ç¬¬åç§ï¼System.out.println(System.getProperty("user.dir"));ç»æï¼C:\Documents and Settings\Administrator\workspace\projectName
è·åå½åå·¥ç¨è·¯å¾ç¬¬äºç§ï¼System.out.println( System.getProperty("java.class.path"));ç»æï¼C:\Documents and Settings\Administrator\workspace\projectName\binè·åå½åå·¥ç¨è·¯å¾
温馨提示:答案为网友推荐,仅供参考