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() methodClass cl = Class.forName("GetSystemResourceOfClass");// Get ClassLoader by using ClassLoaderClassLoader loader = cl.getClassLoader();// It return URL with the given resource nameURL address = loader.getSystemResource("E://Programs//getProperties.doc");// Display address of the resourceSystem.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
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Java ClassLoader getSystemResource()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring 事务失效的 8 大场景,面
- 下一篇: c++重载++运算符_C ++运算符重载