I want to get directory path like d:/test/config.conf of a resource in servlet.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Yasir_Khan
Posted On:   Saturday, November 3, 2001 01:32 AM

i have a file config.conf placed in a directory say d:/test, i want to write a method which will take resource name as parameter and return complete directory path of resource e.g. I have resource d:/test/config.conf and want that when i call getPath("config.conf"); it should returns d:/test/config.conf. I have one implementation of getPath() /////////*************/////////// public String getPath(String FileName){ try{ java.net.URL url = super.getClass().getResource("/"+FileName); String path=""; if(url != null){ path=url.getFile(); return path; }else{    More>>

i have a file config.conf placed in a directory say d:/test, i want to write a method which will take resource name as parameter and return complete directory path of resource e.g.
I have resource d:/test/config.conf
and want that when i call getPath("config.conf"); it should returns d:/test/config.conf.
I have one implementation of getPath()


/////////*************///////////


public String getPath(String FileName){


try{


java.net.URL url = super.getClass().getResource("/"+FileName);


String path="";


if(url != null){

path=url.getFile();

return path;


}else{

System.out.println("getPath() --> Resource Not Found");


return null;


}


}catch(Exception ex){

System.out.println("getPath() --> Exception "+ex);


return null;


}


}


/////////*************///////////

but it works fine if used in a java application program, but in servlet it returns some server specific URL like
/apps/yoursite.com/resources/config.conf

but i want
d:/test/config.conf

any help will be appreciated ...
Thanx ......
Yasir

   <<Less
About | Sitemap | Contact