Home » Java programming language

Java ClassLoader findResources() method with example

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

ClassLoader Class findResources() method

  • findResources() method is available in java.lang package.
  • findResources() method is used to find all the resources with the given resource name in the enumeration of URL objects.
  • 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() method may throw an exception at the time of finding the resources.
    IOException: This exception may throw during I/O error.


    protected Enumeration findResources(String resource_name);


  • String resource_name – represents the name of the resource.

Return value:

The return type of this method is Enumeration, it returns an enumeration of URL object for the given resources.


// Java program to demonstrate the example 
// of Enumeration findResources(String resource_name)
// method of ClassLoader 

import java.util.*;

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());
                System.out.println("Resources Not Found!!!");
        } catch (IOException ex) {

public class Main {
    public static void main(String[] args) throws Exception {
        // Creating an instance of FindResources
        FindResources fr = new FindResources();


Resources Found: [email protected]


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.