dcsimg
getClassLoader().getResource(file name)
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Bhabani_Nayak
Posted On:   Monday, July 31, 2006 08:31 AM

Hi frnds,

I am trying to retrieve the path of a file using getClassLoader().getResource method. But in the output it is giving some garbage value in between the result path. In the directory structure of the file, in one of the directory I have given a space in between the character of the directory name.
I want to know is it the space that is creating problem for the path...
plz guide me as soon as possible..
Bhabani

Re: getClassLoader().getResource(file name)

Posted By:   Madhusudhan_Rao  
Posted On:   Monday, August 21, 2006 05:16 AM

Here the sample code , hope it may help

import java.net.URL;



public class FindResource {



public FindResource() {



String path = FindResource.class.getClassLoader().getResource("findfile.txt").getPath();


System.out.println(" Path :" + path);


}



public static void main(String args[]) {


new FindResource();


}


}



findfile.txt is the file whose path i want to extract.
make sure it is in the same folder where u r stroing this
java file. Or else it will throw NullPointerException

if u r using servlet , then make use of the ServletContext to find the file.

About | Sitemap | Contact