码迷,mamicode.com
首页 > 编程语言 > 详细

java Resource

时间:2014-07-14 14:36:17      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:http   java   使用   文件   io   re   

ClassPathResource:

  String resource = ""; //相对路径

  Resource resource = new ClassPathResource(resource);

  //获取当前类下,同一个包中的资源

  Resource resource = new ClassPathResource("文件名称",this.getClass());

FileSystemResource:

  String resource = "";

  //文件系统的真实路径

   Resource resource = new FileSystemResource(resource);

UrlResource:

    String resource = "httP://...";

      resource = "file://c:/applic...";

     Resource resource = new UrlResource("file://c:/applicationContext.xml");

ServletContextResource:

  需要在web环境中才可以

   Resource resource = new ServletContextResource(servletContext,"/WEB-INF/classes/applicationContext.xml");

 

我们在使用spring容器的时候,由于applicationContext是beanFactory子类,封装了更多方法功能供我们调用,所以在使用applicationContext时,会使用特定格式的字符串表示各种类型

classPath:loaded from the classpath

file:loaded as a URL,from the fileSystem

http:  loaded as a URL

none   /data/config.xml    Depends on the underlying ApplicationContext

java Resource,布布扣,bubuko.com

java Resource

标签:http   java   使用   文件   io   re   

原文地址:http://www.cnblogs.com/cr1719/p/3841853.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!