Java Class getResource() Method

The getResource() method of java Class class is used to return the resources of the module in which this class exists. The value returned from this function exists in the form of the object of the URL class.

Syntax

Parameter

name - the name of the desired resource

Returns

A URL object.

Throws

NullPointerException

Example 1

Test it Now

Output:

Value URL = null
Value URL = file:/C:/Users/Suman/Documents/NetBeansProjects/calendar/build/classes/Class/file1.txt

Example 2

Test it Now

Output:

Value URL = file:/C:/Users/Suman/Documents/NetBeansProjects/calendar/build/classes/Class/file1.txt
Value URL = file:/C:/Users/Suman/Documents/NetBeansProjects/calendar/build/classes/Class/newfolder/file2.txt

Next TopicJava Class




Latest Courses