Home » Java programming language

Java ClassLoader getSystemResource() method with example

ClassLoader Class getSystemResource() method: Here, we are going to learn about the getSystemResource() method of ClassLoader Class with its syntax and example.
Submitted by Preeti Jain, on November 29, 2019

ClassLoader Class getSystemResource() method

  • getSystemResource() method is available in java.lang package.
  • getSystemResource() method is used to find the system resource of the given resource name from the searching location to load classes.
  • 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() method does not throw an exception at the time of returning URL.

Syntax:

    public URL getSystemResource (String resource_name);

Parameter(s):

  • String resource_name – represents the name of the resource.

Return value:

The return type of this method is URL, it returns the following values based on the given cases,

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

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






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.