ITeye博客

关于Java中的getResource()方法

zealotds · 2010-08-23 23:28 · java · 编程语言 · HTML · Java · Access · Oracle · Security · Markdown

本文摘机自 [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 /. [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 "." 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)

暂无评论。

评论功能维护中,当前仅展示历史评论。