ClassLoader类的getResources()方法 (ClassLoader Class getResources() method)

  • getResources() method is available in java.lang package.

    getResources()方法在java.lang包中可用。

  • getResources() method is used to identify all the resources with the given resource name.

    getResources()方法用于标识具有给定资源名称的所有资源。

  • getResources() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    getResources()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • getResources() method may throw an exception at the time of returning resource.

    getResources()方法在返回资源时可能会引发异常。

    IOException: This exception may throw during I/O operations.

    IOException :在I / O操作期间可能会引发此异常。

Syntax:

句法:

    Enumeration getResources(String resource_name);

Parameter(s):

参数:

  • String resource_name – represents the name of the resource.

    字符串resource_name –表示资源的名称。

Return value:

返回值:

The return type of this method is Enumeration, it returns Enumeration of URL object for scanning the resource otherwise it returns null when the given resource does not exist.

此方法的返回类型为Enumeration ,它返回用于扫描资源的URL对象的Enumeration,否则在给定资源不存在时返回null。

Example:

例:

// Java program to demonstrate the example
// of Enumeration getResources(String resource_name)
// method of ClassLoader
import java.net.*;
import java.util.*;
public class GetResourcesOfClassLoader {public static void main(String args[]) throws Exception {// It loads the class
Class cl = Class.forName("GetResourcesOfClassLoader");
// It returns the class loader associated with
// the given class
ClassLoader loader = cl.getClassLoader();
// Display Loader Class
System.out.println("Loader Class : ");
System.out.println(loader.getClass());
System.out.println();
// It returns the resources associated with this Class
// GetResourcesOfClassLoader
Enumeration en = loader.getResources("getProperties().doc");
// Display Resources
System.out.println("Class Resources : ");
while (en.hasMoreElements())
System.out.println(en.nextElement());
}
}

Output

输出量

Loader Class :
class jdk.internal.loader.ClassLoaders$AppClassLoaderClass Resources :

翻译自: https://www.includehelp.com/java/classloader-getresources-method-with-example.aspx

Java ClassLoader getResources()方法与示例相关推荐

  1. java getresources方法_Java ClassLoader getResources()方法与示例

    ClassLoader类getResources()方法getResources()方法在java.lang包中可用. getResources()方法用于标识具有给定资源名称的所有资源. getRe ...

  2. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  3. java getresources方法_Java Application.getResources方法代码示例

    import android.app.Application; //导入方法依赖的package包/类 /** * Init the framework * * @param application ...

  4. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  5. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  6. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  7. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  8. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  9. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

最新文章

  1. 用Jmeter制造软件测试数据
  2. 供销合作社对话中国农民丰收节交易会 谋定为农服务主业
  3. [Asp.Net+C#]Datagrid使用技巧一(怎样灵活控制表头)
  4. ArcGIS实验教程——实验二十五:大型商场选址经典案例
  5. 流浪不是我的初衷 ... ...
  6. UNIX高手的10个习惯之一
  7. pscp使用详解 Windows与Linux文件互传工具
  8. 占位符是如何防止sql注入的?
  9. libjpeg php,libjpeg62_turbo
  10. iphone分辨率中的scale参数
  11. 基于R语言的主成分分析
  12. ArcGIS中相对高程的提取
  13. EBS Form开发中LOV实现实例
  14. 信用飞疑似信息泄露致用户被骗近4万元,平台借款利率高达75%
  15. 物理学的困惑: 弦理论崛起了, 科学却衰落了
  16. “逐日之弓”AI 光伏开发大赛培训开启 Imagination解读AI处理器创新应用
  17. 公有云 私有云及架构
  18. 计算机语言发展简史,计算机语言发展简史
  19. SAS概念知识点 (复习1)
  20. linux:单用户模式修改密码

热门文章

  1. 世上最简单的mysql_mysql这样学最简单|基本操作上
  2. linux课堂笔记(4)
  3. vs 选定内容没有属性页_从智能单品,到全屋智能:2019中国智能家居发展白皮书【附82页PPT】...
  4. windows, 放方向键设置为vim格式,autohotkey-windows
  5. Nginx(七):nginx原理解析
  6. MIP 组件库升级公告
  7. Angular6_服务端渲染SSR
  8. Android4.0设置界面修改总结
  9. ES6 学习笔记(一)let,const和解构赋值
  10. IIS 伪静态下 利用PHP获取 网址后缀