Java ClassLoader findResources()方法與示例

ClassLoader類findResources()方法 (ClassLoader Class findResources() method)

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

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

  • findResources() method is used to find all the resources with the given resource name in the enumeration of URL objects.

    findResources()方法用于在URL對象的枚舉中查找具有給定資源名稱的所有資源。

  • findResources() 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.

    findResources()方法是一個非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • findResources() method may throw an exception at the time of finding the resources.

    findResources()方法在查找資源時可能會引發異常。

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

    IOException :在I / O錯誤期間可能引發此異常。

Syntax:

句法:

    protected Enumeration findResources(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 an enumeration of URL object for the given resources.

此方法的返回類型為Enumeration ,它返回給定資源的URL對象的枚舉。

Example:

例:

// Java program to demonstrate the example 
// of Enumeration findResources(String resource_name)
// method of ClassLoader 
import java.util.*;
import java.io.*;
class FindResources extends ClassLoader {
void findResources() {
try {
// It checks whether the given resources is found
// or not by using the findResources()
Enumeration en = super.findResources("getProperties().doc");
// If en not null that means en found
// then don't need to load again
if (en != null)
System.out.println("Resources Found: " + en.toString());
else
System.out.println("Resources Not Found!!!");
} catch (IOException ex) {
System.out.println(ex.toString());
}
}
}
public class Main {
public static void main(String[] args) throws Exception {
// Creating an instance of FindResources
FindResources fr = new FindResources();
fr.findResources();
}
}

Output

輸出量

Resources Found: [email?protected]

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541937.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541937.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541937.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Java ByteArrayInputStream mark()方法與示例

ByteArrayInputStream類mark()方法 (ByteArrayInputStream Class mark() method) mark() method is available in java.util package. mark()方法在java.util包中可用。 mark() method is used to set the current mark position in the stream from where read or write can b…

java mediainfo.dll_MediaInfo庫的簡單使用

想到一個問題, 如何獲得一個圖像文件(比如jpg, bmp, png)的信息. 自己查查文件的格式, 寫一個解析, 應該不困難; 但是找了下現成的, 發現MediaInfo庫已經可以非常好的實現需要的功能了.MediaInfo可以在sourceforge上找到, 是一個解析視頻,音頻, 圖片等媒體文件的庫. 可以得到文…

Redis配置和常用命令

1 redis.conf配置文件:2 引用3 #是否作為守護進程運行4 daemonize yes5 #配置pid的存放路徑及文件名,默認為當前路徑下6 pidfile redis.pid7 #Redis默認監聽端口8 port 63799 #客戶端閑置多少秒后,斷開連接 10 timeout 300 11 #日志顯示級別 …

oracle中dbms_DBMS中的功能依賴性和屬性關閉

oracle中dbms功能依賴 (Functional Dependency) A relational Database management System (RDBMS) represents the database o a collection of relations/tables. A functional dependency is a constraint between two sets of attributes in a relation. It is the propert…

java invoke 泛型_利用Java反射機制和泛型,全自動解析json

有啦這個簡直,太爽啦,利用Java 反射機制,利用Class 就可以得到 類的 變量 Field[] fieldscls.getDeclaredFields();還可以通過類中 的方法名字 去執行這個方法m1 cls.getDeclaredMethod(getMothodName(fields[j].getName()), String.class)…

2_C語言中的數據類型 (四)整數與無符號數

1.1 sizeof關鍵字 sizeof是c語言關鍵字,功能是求指定數據類型在內存中的大小,單位:字節 sizeof與size_t類型 1.1 int類型 1.1.1 int常量,變量 int就是32位的一個二進制整數,在內存當中占據4個字節…

python 示例_Python TextCalendar類別| pryear()方法與示例

python 示例Python TextCalendar.pryear()方法 (Python TextCalendar.pryear() Method) pryear() method is an inbuilt method of the TextCalendar class of calendar module in Python. It works on text calendars. It uses an instance of TextCalendar class and prints …

Spring實戰——通過Java代碼裝配bean

上篇說的是無需半行xml配置完成bean的自動化注入。這篇仍然不要任何xml配置,通過Java代碼也能達到同樣的效果。 這么說,是要把上篇的料拿出來再煮一遍? 當然不是,上篇我們幾乎都在用注解的方式如ComponentScan Component等就完成了…

java 謂詞_java8-謂詞(predicate)

傳遞代碼我們首先看一個例子,假設你有一個 Apple 類,它有一個getColor方法,還有一個變量inventory保存著一個Apples的列表。你可能想要選出所有的綠蘋果,并返回一個列表。通常我們用篩選(filter)一詞來表達這個概念。在 Java 8之前…

getlong_Java LocalDateTime類| 帶示例的getLong()方法

getlongLocalDateTime類的getLong()方法 (LocalDateTime Class getLong() method) getLong() method is available in java.time package. getLong()方法在java.time包中可用。 getLong() method is used to get the value as long for the given temporal field from this dat…

java.io和util的區別_Java NIO與IO的區別和比較

Java NIO與IO的區別和比較導讀J2SE1.4以上版本中發布了全新的I/O類庫。本文將通過一些實例來簡單介紹NIO庫提供的一些新特性:非阻塞I/O,字符轉換,緩沖以及通道。一. 介紹NIONIO包(java.nio.*)引入了四個關鍵的抽象數據類型,它們共…

Java LocalDate類| isSupported()方法與示例

LocalDate類isSupported()方法 (LocalDate Class isSupported() method) Syntax: 句法: public boolean isSupported (TemporalField t_field);public boolean isSupported (TemporalUnit t_unit);isSupported() method is available in java.time package. isSupp…

區塊鏈+稅務的思考

2016年,區塊鏈技術火了!各大金融公司、互聯網巨頭都競相參加到區塊鏈技術的研究中。我們公司的業務是稅務的信息化領域,也希望通過區塊鏈技術的應用,來提升為財稅領域的服務。 區塊鏈技術優缺點總結 下圖是對區塊鏈技術的一些特點…

java hasset 順序_java集合排序問題

List: 元素是有序的,元素可以重復,因為該集合體系有索引(腳標)常用的子類對象:1————ArrayList 底層的數據結構是使用的數組結構特點:查詢速度快,但是增刪比較慢2————LinkedList底層的數據結構使用的是鏈表結構…

如何使用JavaScript刪除CSS屬性?

In this article, well see how we can remove a CSS property from a certain element using JavaScript? We can remove only those properties that we assign ourselves and the pre-default ones cannot be removed by this method. 在本文中,我們將看到如何使…

Django 緩存系統

Django 是動態網站,一般來說需要實時地生成訪問的網頁,展示給訪問者,這樣,內容可以隨時變化,但是從數據庫讀多次把所需要的數據取出來,要比從內存或者硬盤等一次讀出來 付出的成本大很多。 緩存系統工作原理…

java web截屏_java_WebDriver中實現對特定的Web區域截圖方法,用過 WebDriver 的同學都知道,We - phpStudy...

WebDriver中實現對特定的Web區域截圖方法用過 WebDriver 的同學都知道,WebDriver 可以對瀏覽器中的頁面進行截圖。例如:public byte[] takeScreenshot() throws IOException {TakesScreenshot takesScreenshot (TakesScreenshot) driver;return takesSc…

c語言 關鍵字const_C ++ const關鍵字| 查找輸出程序| 套裝1

c語言 關鍵字constProgram 1: 程序1&#xff1a; #include <iostream>using namespace std;void fun(int& A) const{A 10;}int main(){int X 0;fun(X);cout << X;return 0;}Output: 輸出&#xff1a; [Error] non-member function void fun(int) cannot ha…

【喜報】JEEWX榮獲“2016 年度碼云新增熱門開源軟件排行榜”第一名!

為什么80%的碼農都做不了架構師&#xff1f;>>> 2016 年度碼云新增項目排行榜 TOP 50 正式出爐&#xff01;根據 2016 年在碼云上新增開源項目的 Watch、Star、Fork 數量以及其他角度的統計&#xff0c;JEEWX捷微管家榮獲“2016 年度碼云新增熱門開源軟件排行榜”第…