How can I create a file in a servlet? The code below is in my doPost method, but it doesn't work.
File file = new File("testing.txt");
Bear Bibeault wrote:Does it cause your computer to explode? What does "doesn't work" mean?
That asked, you're not specifying any file path.
No, it didn't explode yet. =)
It works using absolute path "....../jfreechartweb/images/testing.txt".
I'll try to make it work using relative path (if it's possible, of course =)
Leandro Coutinho wrote:I'll try to make it work using relative path (if it's possible, of course =)
Of course a relative path (like the one you tried) is relative to the current working directory. It would be easy to find out what that is for your servlet container, but it might be different for some other servlet container. So you shouldn't really rely on finding out what it is. Not to mention that putting files in that directory might be pointless -- I don't know why you would want to do it anyway.