关于Java中的getResource()方法

本文摘机自 [url=http://download-llnw.oracle.com/javase/1.4.2/docs/guide/resources/resources.html][size=large]Accessing Resources in a Location-Independent Manner[/size][/url]

tag: java,resource,location independent

[size=large]Resource:[/size]
/ separated string
/<shortName>.<extension>

[size=large]System Resource:[/size]
CLASSPATH
A resource may be found in a different entry in CLASSPATH than where the class is loaded

[size=large]Class Loader:[/size]
all class loaders search for a resource as system resource firstly
AppletClassLoader - system resource > JAR > CODEBASE > remote

[size=large]Resouce Name:[/size]
replace "." with "/" in fully qualified package name
and add resource name as "<name>.<ext>"
absolute name starts with "/", otherwise it is relative

[size=large]Manipulating Resource:[/size]
return null when not exist or permission denied
use URL.openStream to open the returned URL
use (ImageProducer)URL.getContent to get image stored in the Resource

[size=large]Security:[/size]
return null when in security context addresses existence attacks
ClassLoader will not provide access to the contents of a .class file
no restriction regarding non-system class loader found resource
resource [b]in directory[/b] - getResource() use File.exists() which use checkRead() in the security manager
resource [b]in JAR[/b] - succeed for all files regardless of system or non-system class
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值