1. 程式人生 > >關於讀取properties文件路徑問題

關於讀取properties文件路徑問題

rop init tex pre prope 關於 tst fis ext

 1 1.方法一 
 2 InputStream fis =TestProperties.class.getClassLoader().getResourceAsStream(“init.properties”)
 3 
 4 2.方法二(要求TestProperties和init.properties在同一目錄下) 
 5 InputStream fis =TestProperties.class.getResourceAsStream(“init.properties”)
 6 
 7 3.方法三,對於Web工程也可以這樣。 
 8 先獲取ServletContext,然後 
 9 
10
InputStream in=context.getResourceAsStream(“/WEB-INF/classes/init.properties”);

關於讀取properties文件路徑問題