This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript 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: 42972
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!