• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

writing to a file in /WEB-INF/ from a servlet

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, I have got short and simple question. Can I write to a file which is in /WEB-INF/ from a servlet? I have got an application, in which in one part I'm reading from a file, using context.getResourceAsStream(fileName), and in another part I wanted to write TO a file, but I can't find a method thanks to which I could to this. Is there some kind of method which could help me?
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. You can write to a file there.
 
Tom Kowalski
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And could somebody write how? ^^ Please...

I have been also trying something like this:


but GlassFish is throwing an error: java.net.UnknownServiceException: protocol doesn't support output
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just open a file and write to it.
 
Bosun Bello
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd suggest you take a look at the File I-O package.
 
Tom Kowalski
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just needed a portable way to get address of this file, It seems to me that this should work context.getRealPath(fileName).

Anyway, now I'm wondering, if context.getResourceAsStream(fileName) has got some advantages over normal IO functions.

Thanks.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works for resources--anything on the classpath, including things packaged inside JAR files. File IO doesn't.
 
Tom Kowalski
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, sorry, last thing (I know David that I'm making you angry ^^)

My idea with


is not working good, because it`s returning something like this:
F:\WI\build\web\WEB-INF\oceny\plik.txt

and it should return this:
F:\WI\web\WEB-INF\oceny\plik.txt (without 'build' inside)

(I'm using NetBeans).
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If that's the path it's returning then it's probable that it's correct, and NetBeans is deploying from its build directory.
 
Tom Kowalski
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, sorry for problem.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic