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