Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to give file path in java class

 
bharat salunkhe
Greenhorn
Posts: 25
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi can any one tell me how to give xml file path in java class not in servlet ! m working on web app so that path should be applicable for .war also.. thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65537
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which XML file? And with a .war file, there is no file path.

What are you actually trying to accomplish?
 
bharat salunkhe
Greenhorn
Posts: 25
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Bear for reply..
actually am using xml file for my menu and i gave path in my class something like this "D:/maydata.xml" (its working fine) so i want to add this file in my project directory e.g WEB-INF or anywhere so where should i add this file and how should i give path in my java class???
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65537
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't be using an absolute file path at all.

Place the file somewhere within the web app, and use ServletContext.getResourceAsStream() to open a stream to it.
 
bharat salunkhe
Greenhorn
Posts: 25
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You shouldn't be using an absolute file path at all.

Place the file somewhere within the web app, and use ServletContext.getResourceAsStream() to open a stream to it.


thats the problem am accessing that file within class not in servlet so how could i get servletContext ?? is there any other way?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65537
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could place the file in the classpath instead (WEB-INF/classes) and use the class loader's method via Class.getResourceAsStream()
 
bharat salunkhe
Greenhorn
Posts: 25
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You could place the file in the classpath instead (WEB-INF/classes) and use the class loader's method via Class.getResourceAsStream()

thanks Bear ..
issue resolved !!
 
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!