Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

read a file for text file under WEB-INF  RSS feed

 
Timotius Pamungkas
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Can I read a file under WEB-INF and put ir into java.io.File?
I've tried following code, but the file.exists() always returns false. What can I do?






I need the file to be read from my backing bean (as static property in backing bean)
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The File constructor needs a pathname or "file:///" URL, not an HTTP URL. You need to convert the web path to a real path by something like ServletContext.getRealPath("/WEB-INF/properties/test.txt"). You need to think about how to get the real path into the backing bean (which doesn't have access to the ServletContext).
 
Timotius Pamungkas
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works fine...

I access the ServletContext via FacesContext.getCurrentInstance()

Thanks for the answer
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!