Java ClassLoader getSystemResource()方法与示例

ClassLoader类getSystemResource()方法 (ClassLoader Class getSystemResource() method)

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

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

  • getSystemResource() method is used to find the system resource of the given resource name from the searching location to load classes.

    getSystemResource()方法用于从搜索位置查找给定资源名称的系统资源以加载类。

  • getSystemResource() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get any error.

    getSystemResource()方法是一个静态方法,可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会出现任何错误。

  • getSystemResource() method does not throw an exception at the time of returning URL.

    返回网址时, getSystemResource()方法不会引发异常。

Syntax:

句法:

    public URL getSystemResource (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 URL, it returns the following values based on the given cases,

此方法的返回类型为URL ,它根据给定的情况返回以下值,

  • It returns the URL when any system resource associated with the given name exists.

    当存在与给定名称关联的任何系统资源时,它将返回URL。

  • It returns null, when no system resource associated with the given name exists.

    当不存在与给定名称关联的系统资源时,它返回null。

Example:

例:

// Java program to demonstrate the example 
// of URL getSystemResource (String resource_name) method 
// of ClassLoader 
import java.net.*;
public class GetSystemResourceOfClass {
public static void main(String[] args) throws Exception {
// Get Class by using forName() method
Class cl = Class.forName("GetSystemResourceOfClass");
// Get ClassLoader by using ClassLoader
ClassLoader loader = cl.getClassLoader();
// It return URL with the given resource name
URL address = loader.getSystemResource("E://Programs//getProperties.doc");
// Display address of the resource
System.out.print("URL of System Resources : ");
System.out.println(address);
}
}

Output

输出量

URL of System Resources : file:/E:/Programs/getProperties().doc

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/545526.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

操作系统(王道笔记第三章内存)

第三章内存3.1_1内存的基础知识(1)什么是内存:略(2)进程运行的基本原理①从写程序到程序运行②链接③装入3.1_2内存管理的概念(1)内存管理管哪几个方面(2)内存保护①上下…

按钮button加超链接

突然想做一个普通按钮&#xff0c;然后让按钮超链接到别的页面&#xff0c;不知道怎么搞&#xff0c;不过还是在百度找到了。1.如果让本页转向新的页面则用&#xff1a;<input typebutton οnclick"window.location.href(连接)"> 2.如果需要打开一个新的页面进…

Redis 快速搭建与使用

Redis 是由 C 语言开发的开源内存数据存储器&#xff0c;经常被用作数据库、缓存以及消息队列等。 Redis 因为其强大的功能和简洁的设计&#xff0c;深受广大开发者和公司的喜爱&#xff0c;几乎占领了内存数据库市场的所有份额。 1 Redis 特性 Redis 有很多优秀的特性&#…

如何计算Python中列表项的出现次数?

The python count() method counts the number of occurrences of an element in the list and returns it. python count()方法对列表中某个元素的出现次数进行计数并返回它。 Syntax: 句法&#xff1a; list.count(x)The count() method takes a single argument, x, whose…

网页自动关闭的代码

<script language"javascript">window.openernull; window.open(, _self, );//模拟自己打开自己window.close();//再关闭就没有对话框了</script>--------------------------以下是过多少秒自动关闭网页,弹窗<html><head><title>JS定时…

hibernate annotation注解方式来处理映射关系

2019独角兽企业重金招聘Python工程师标准>>> 在hibernate中&#xff0c;通常配置对象关系映射关系有两种&#xff0c;一种是基于xml的方式&#xff0c;另一种是基于annotation的注解方式&#xff0c;熟话说&#xff0c;萝卜青菜&#xff0c;可有所爱&#xff0c;每个…

操作系统Ubuntu(实验一二)

摘录&#xff1a;https://www.cnblogs.com/penglang14/p/10632360.html 实验一二1.1_小技巧1.2_ls查看目录命令1.3_cd切换目录命令1.4_查看文件内容命令(1)cat filename(2)more filename(3)head [-n] filename([]表示此内容可有可无)&#xff08;4&#xff09;wc命令确定行数、…

Redis 是如何执行的?

在以往的面试中&#xff0c;当问到一些面试者&#xff1a;Redis 是如何执行的&#xff1f;收到的答案往往是&#xff1a;客户端发命令给服务器端&#xff0c;服务端收到执行之后再返回给客户端。然而对于执行细节却「避而不谈」 &#xff0c;当继续追问服务器端是如何执行的&am…

java 枚举迭代_Java中的枚举和迭代器之间的区别

java 枚举迭代Java中的枚举与迭代器 (Enumeration vs Iterator in Java) Here, we will see how Enumeration differs from Iterator? 在这里&#xff0c;我们将看到Enumeration与Iterator有何不同&#xff1f; 1)枚举 (1) Enumeration) Enumeration is an interface which i…

ORA-14551: 无法在查询中执行 DML 操作

最近在调试一个带DML操作的函数时&#xff0c;一直不成功&#xff0c;在PL/SQL中测试时没问题&#xff0c;通过SQL语句调用函数时就不行了&#xff0c;刚开始一直没找到原因&#xff0c;后来无意间把 函数中捕获异常的代码注释掉&#xff0c;终于通过SQL调试时&#xff0c;弹出…

第五章I/O管理

I/O章节5.1.1I/O分类&#xff08;1&#xff09;按使用特性分&#xff08;2&#xff09;I/O设备按传输速率分类&#xff08;3&#xff09;I/O设备按信息交换的单位分5.1.2I/O控制器5.1.3I/O控制方式&#xff08;1&#xff09;程序直接控制方式&#xff08;轮询&#xff09;&…

阿里巴巴分布式服务框架 Dubbo

1.Dubbo是阿里巴巴内部的SOA服务化治理方案的核心框架&#xff0c;每天为2000 个服务提供3,000,000,000 次访问量支持&#xff0c;并被广泛应用于阿里巴巴集团的各成员站点。Dubbo自2011年开源后&#xff0c;已被许多非阿里系公司使用。 2.入门文档 http://alibaba.github.io/d…

列表使用与内部实现原理

列表类型 (List) 是一个使用链表结构存储的有序结构,它的元素插入会按照先后顺序存储到链表结构中,因此它的元素操作 (插入\删除) 时间复杂度为 O(1),所以相对来说速度还是比较快的,但它的查询时间复杂度为 O(n),因此查询可能会比较慢。 1 基础使用 列表类型的使用相对来…

c ++查找字符串_C ++类和对象| 查找输出程序| 套装1

c 查找字符串Program 1: 程序1&#xff1a; #include <iostream>using namespace std;class Sample {privateint A;privateint B;publicvoid init(){A 10;B 20;}publicvoid print(){cout << A << " " << B;}};int main(){Sample S;S.init…

Oracle 练习P297 131026 PL/SQL块程序

--1、编写一个PL/SQL块&#xff0c;输出所有员工的员工姓名&#xff0c;员工号、工资和部门号。beginfor v_emp in (select * from emp) loopdbms_output.put(员工姓名&#xff1a; || v_emp.ename);dbms_output.put(&#xff0c;员工号&#xff1a; || v_emp.empno);dbms_outp…

操作系统习题

操作系统习题习题一一、选择习题二一、选择二、综合题习题三一、选择题&#xff1f;二、简答题进程互斥遵循的四个原则&#xff1a;空闲让进、忙则等待、有限等待、让权等待重点习题四一、选择&#xff1f;&#xff1f;二、综合题死锁产生的 4 个必要条件是&#xff1a; &#…

WCF trace、log

1. 打开wcf配置&#xff1a; &#xff12;. enable trace &#xff0c; log 可以改变log路径&#xff1a; &#xff13;. 用 SvcTraceViewer.exe &#xff08;直接在c盘下搜索&#xff09; 查看 &#xff14;. 如果想自定义trace&#xff1a; catch(Exception ex) { Trace.Writ…

字典使用与内部实现原理

字典类型 (Hash) 又被成为散列类型或者是哈希表类型,它是将一个键值 (key) 和一个特殊的“哈希表”关联起来,这个“哈希表”表包含两列数据:字段和值。例如我们使用字典类型来存储一篇文章的详情信息,存储结构如下图所示: 同理我们也可以使用字典类型来存储用户信息,并且…

游标复习笔记

--while循环访问游标declarecursor cur_dept isselect * from dept;v_dept cur_dept%rowtype;beginopen cur_dept;fetch cur_dept into v_dept;while cur_dept%found loopdbms_output.put_line(v_dept.dname);fetch cur_dept into v_dept;end loop;close cur_dept;end;--retur…

操作系统中同步_操作系统中的经典同步问题

操作系统中同步经典同步问题 (Classical synchronization problem) In this section, we present a number of different philosopher synchronization problems that are important mainly because they are examples for a large class of concurrency- control problems. Th…