.properties文件格式
version=v1.0
developer=kuoa
welcome=Welcome to use KFTP!
defaultDir=D\:\\KFTP
獲取.properties文件中的值
1> 方式一
☞ 該文件放在項目src文件夾中,該方法中直接傳入文件名即可( 不包含後綴 )
ResourceBundle rb = ResourceBundle.getBundle("info");
rb.getString(key);
2> 方式二
☞ 將.properties文件放在單獨的文件夾中
|- ResourceBundle
|- PropertyResourceBundle
// 獲取properties文件在項目中的全路徑
// 將其放入config文件夾中
String proFilePath = System.getProperty("user.dir") + "\\config\\info.properties";
// 根據全路徑獲取輸入流
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(proFilePath));
// 參數類型爲InputStream
ResourceBundle rb = new PropertyResourceBundle(bufferedInputStream);
// 使用rb對象獲取數據
String value1 = rb.getString("version");