Java讀取resource文件/路徑的幾種方式

有時候想獲取放在工程resources 文件下的文件路徑,下面是幾種方法:web

1.ide

String fileName = this.getClass().getClassLoader().getResource("文件名").getPath();//獲取文件路徑  
String fileUtl = this.getClass().getResource("文件名").getFile();this

示例路徑結果:/E:/idea_work/sofn-qry-web/target/classes/CityJson.jsidea

2..net

File directory = new File("");//參數爲空
String courseFile = directory.getCanonicalPath()//標準的路徑 ;
String author =directory.getAbsolutePath()//絕對路徑;
示例路徑結果:E:\idea_work\sofn-qry-webblog



原文:https://blog.csdn.net/oschina_40188932/article/details/78833754

get

相關文章
相關標籤/搜索