• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

read a file for text file under WEB-INF

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Works fine...

I access the ServletContext via FacesContext.getCurrentInstance()

Thanks for the answer
reply
    Bookmark Topic Watch Topic
  • New Topic