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.


    public URL getSystemResource (String resource_name);


  • 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.


// Java program to demonstrate the example 
// of URL getSystemResource (String resource_name) method 
// of ClassLoader 


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 : ");


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


Comments and Discussions



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

© some rights reserved.