• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Tom Kowalski
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • 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?
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just open a file and write to it.
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks, sorry for problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic