記錄錯誤,打開文件流一定要關閉並重新打開文件流,不然取的文件內容永遠是第一次取的文件內容:
1 /** 2 * 讀取配置文件 3 */ 4 private Properties readProperties() { 5 Properties properties = new Properties(); 6 try { 7 InputStream inputStream = new FileInputStream(filePath); 8 BufferedInputStream in = new BufferedInputStream(inputStream); 9 properties.load(in); 10 inputStream.close(); 11 in.close(); //關閉文件流 12 } catch (IOException e) { 13 e.printStackTrace(); 14 } 15 return properties; 16 }