講述java讀取properties文件的方法
講述java讀取properties文件的方法
1.不在項目中讀。
Properties properties = new Properties();BufferedReader read = new BufferedReader(new InputStreamReader(new FileInputStream("文件的路徑"),"utf-8"));properties.load(read);properties .getProperty("那個文件的key")
2.在項目中讀取:
InputStream inputStream =你那工具類的類名.class.getResourceAsStream("/文件名.properties");Properties p = new Properties();try {p.load(inputStream);inputStream.close();} catch (IOException e1) {e1.printStackTrace();}
都是通過p.getProperty(配置文件里的key)獲得value的'
希望本文所述對大家的java程序設計有所幫助。
【講述java讀取properties文件的方法】相關文章:
從Java的jar文件中讀取數(shù)據(jù)的方法02-21
Java的jar文件中讀取數(shù)據(jù)的方法09-23
從Java的jar文件中如何讀取數(shù)據(jù)的方法01-24
java如何通過url讀取文件08-24
java讀取解析xml文件實例02-26
Java讀取郵件的方法02-02
java讀取CSV的方法10-05
關于java讀取文件顯示進度條的實現(xiàn)方法01-03
PHP讀取文件的正確方法11-28