通过Spring
      
       工具类获取
      
      
       classpath
      
      
       下的文件资源
      
     
    
     
      1、资源文件不在
      
       jar
      
      
       中
      
     
    
     
      File cfgFile = ResourceUtils.getFile(“classpath:test.txt”);
     
    
     
      或者
     
    
     
      org.springframework.core.io.Resource fileRource = new ClassPathResource(“test.txt”);
     
    
     
      获取文件:
      
       fileRource
      
      .getFile();
     
    
     
      获取文件流:
      
       fileRource
      
      .getInputStream();
     
    
     
      2、资源文件在
      
       jar
      
      
       中
      
     
    
     
      org.springframework.core.io.Resource fileRource = new ClassPathResource(“test.txt”);
     
    
     
      获取文件流:
      
       fileRource
      
      .getInputStream();
     
    
     
      
       注:不管是文件系统中的类资源,还是
       
        JAR
       
       
        中的类资源文件,都可以以流的形式读取
       
      
     
    
     
      参考:
     
    
     
      陈雄华:《使用如下方式读取
      
       JAR
      
      
       中的文件出错》
      
      
       http://stamen.iteye.com/blog/1485531
      
     
    
     
      
       
        http://blog.csdn.net/liu251/article/details/2899023
       
      
     
    
     
      如何读取
      
       JAR
      
      
       包中的资源文件(如
      
      
       XML
      
      
       、
      
      
       TXT
      
      
       等)
      
      
       :
      
      
       
        http://blog.csdn.net/liu251/article/details/4057140
       
      
     
    
     
      
     
    
 
