html透過file獲取檔案路徑方法:
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("").getPath());
結果:
C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin\com\test
獲取當前類的絕對路徑;
html透過file獲取檔案路徑方法:
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("").getPath());
System.out.println(f);
結果:
C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin\com\test
獲取當前類的絕對路徑;