zoukankan      html  css  js  c++  java
  • java中getResourceAsStream的问题 缓存

    运行状态下property文件已经被改动了,但是使用getResourceAsStream()方法读取的文件没发生变化,还是和最初启动服务器时的一致。在网上查了一下,有人说是getResourceAsStream()方法读取新文件后会被java虚拟机缓存,而再次调用getResourceAsStream()方法时会先查找java虚拟机中是否有此文件,如果有则直接返回,如果没有才会去根据传入的name获取文件

     

    1. final Properties prop = new Properties();  
    2.   
    3. Property(String file){  
    4.       
    5.     try {  
    6.         prop.load(this.getClass().getResourceAsStream(file));  
    7.     } catch (FileNotFoundException e) {  
    8.         e.printStackTrace(System.err);  
    9.     } catch (IOException e) {  
    10.         e.printStackTrace(System.err);  
    11.     }  
    12. }  


    应该改为

     

      1. final Properties prop = new Properties();  
      2.   
      3. Property(String file){  
      4.       
      5.     try {  
      6.         prop.load(new FileInputStream(this.getClass().getResource(file).getFile()));  
      7.           
      8.     } catch (FileNotFoundException e) {  
      9.         e.printStackTrace(System.err);  
      10.     } catch (IOException e) {  
      11.         e.printStackTrace(System.err);  
      12.     }  
      13. }  
  • 相关阅读:
    rabiitmq 消息丢失处理
    后端返回文件流和json格式的方式进行文件下载导出
    elasticsearch 安装
    docker-compose 命令
    艾孜尔江的部分影视作品
    游戏作品:万里同风
    Unity设置计时器
    Unity项目中VS Code部分功能出现问题解决思路
    Unity接收FFmpeg的UDP推流
    SVN Basics
  • 原文地址:https://www.cnblogs.com/eggbucket/p/2829523.html
Copyright © 2011-2022 走看看