日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

    歡迎訪問 生活随笔!

    生活随笔

    當前位置: 首頁 >

    Java ClassLoader getSystemResource()方法与示例

    發布時間:2025/3/11 77 豆豆
    生活随笔 收集整理的這篇文章主要介紹了 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()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。