ResourceBundle的路徑問題

昨天突然對.properties文件的路徑產生了懷疑,回家後試了一下,之後對File的相對路徑比較了一下!

System.out.println(System.getProperty("user.dir"));  //這個是去工程的絕對路徑的
  System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));//這個是去當前classpath的uri的!
  new Properties().load(new FileInputStream("test.properties"));//這裏說明test文件在工程的跟目錄下!

new Properties().load(new FileInputStream("test/test.properties"));//說明,在工程底下的test的文件夾底下的文件test.properties!
  ResourceBundle rs = ResourceBundle.getBundle("org.hello");//這裏說明,hello文件就是在於classpath底下的,org包底下有這個文件hello.properties~也就是說.../bin/這個是classpath絕對路徑!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章