-
Read XML from classLoader (3 messages)
- Posted by: Sanket Raut
- Posted on: November 16 2006 02:09 EST
Hi, I have written a method in java class file which loads a resource and displays it contents as : public void getxml(String filename) { ClassLoader cl = this.getClass().getClassLoader(); InputStream inputStream = cl.getResourceAsStream( filename ); int rd=0; try { while((rd=inputStream.read())!=-1) { System.out.print((char)rd); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } I have a jar comprising of following package structure a/b/c/myxml.xml (which is in a jar file which is in the class-path) when i pass a string as a/b/c/myxml.xml the resource is loaded properly. The problem occurs when i pass a string as /a/b/c/myxml.xml Also when the following method is put into a jsp the string /a/b/c/myxml.xml is loaded without any errors. So is there is any difference in policy of loading in case of web-applications? What should be done so that the string /a/b/c/myxml.xml is loaded from a standalone java applicationThreaded Messages (3)
- Re: Read XML from classLoader by Crane Leeon on November 16 2006 09:54 EST
- Re: Read XML from classLoader by arijit dey on November 17 2006 07:23 EST
- Re: Read XML from classLoader by Sanket Raut on November 20 2006 23:07 EST
-
Re: Read XML from classLoader[ Go to top ]
- Posted by: Crane Leeon
- Posted on: November 16 2006 09:54 EST
- in response to Sanket Raut
As I know,'/path/subpath' will take you to root of the current application, and by some case it will take you to the root of your file system. 'path/subpath' is a relative path to the object which invokes it. -
Re: Read XML from classLoader[ Go to top ]
- Posted by: arijit dey
- Posted on: November 17 2006 07:23 EST
- in response to Sanket Raut
If your resource is placed relative to your current programm, use relative path dont use /a/b..if its there in the root level, then specify a / before the path, the path will be resolved relative to / or root. Remember in linux, root means /. cheers, http://www.javaicillusion.blogspot.com/ -
Re: Read XML from classLoader[ Go to top ]
- Posted by: Sanket Raut
- Posted on: November 20 2006 23:07 EST
- in response to arijit dey
Thanks for the input guys......... Peace. Sanket Raut