java中打開文件流后要關閉后重新打開


記錄錯誤,打開文件流一定要關閉並重新打開文件流,不然取的文件內容永遠是第一次取的文件內容:

 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     }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM