博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
class与classloader的getResourceAsStream(String name)
阅读量:7115 次
发布时间:2019-06-28

本文共 1255 字,大约阅读时间需要 4 分钟。

Class中的getResourceAsStream(String name)

声明:public InputStream getResourceAsStream(String name) Class类中的getResourceAsStream()的其实也是代理给Classloader中的getResourceAsStream(),只是name代表的资源方式不同。

  1. If the name begins with a '/' ('\u002f'), then the absolute name of the resource is the portion of the name following the '/'.
  2. Otherwise, the absolute name is of the following form: modified_package_name/name Where the modified_package_name is the package name of this object with '/' substituted for '.' ('\u002e').

程序如下:其中getResource()与getResourceAsStream()是一样的。只是用url打开一个输入流。

package zhao.shu.you;        URL url1=class2.getResource("");        System.out.println(url1);        URL url2=class2.getResource("/");        System.out.println(url2);        ClassLoader class11=class1.getClassLoader();        print:file:/D:/java_temp/plug1/out/production/module1/zhao/shu/you/file:/D:/java_temp/plug1/out/production/module1/复制代码

classLoader

直接是当前包的地址,不用是/开头。如果以“/”显示没有相关资源,返回null。程序如下

ClassLoader class11=class1.getClassLoader();        System.out.println(class11.getResource(""));        System.out.println(class11.getResource(""));        Print:file:/D:/java_temp/plug1/out/production/module1/null复制代码

参考: oracle的库文件说明。

转载于:https://juejin.im/post/5d01175f6fb9a07ef3766190

你可能感兴趣的文章
通过提交信息来关闭issue
查看>>
Angular学习笔记之集成三方UI框架、控件
查看>>
leetcode318. Maximum Product of Word Lengths
查看>>
解决“有边框的子元素宽度设定绝对值后,缩放浏览器会错位”的两种方法
查看>>
Node.js 学习之路
查看>>
angular 基于ng-messages的验证
查看>>
三、取get
查看>>
利用PHP实现常用的数据结构之写在前面(小白系列文章一)
查看>>
Zttp - 一个基于 Guzzle Http 的更好用的 PHP HTTP Package
查看>>
使用asprise进行图片验证码识别
查看>>
HTML基本语法和语义
查看>>
解析nodeJS模块源码 亲手打造基于ES6的观察者系统
查看>>
77% 的网站使用了至少有 1 个漏洞的 JavaScript 库
查看>>
ES5新增 数组操作forEach()、map()、filter()、some()、every()
查看>>
一个可以提高开发效率的Git命令-- Cherry-Pick
查看>>
IBM发表论文:可能已找到处理量子计算退相干的方法
查看>>
.NET Core 3.0中的数据库驱动框架System.Data
查看>>
Firefox Quantum支持跨浏览器插件架构
查看>>
Oracle收购Talari,第一家SD-WAN公有云提供商出现
查看>>
数据库设计中的9大常见错误
查看>>