my dog learned polymorphism
The moose likes JSF and the fly likes Writing to a text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Writing to a text file" Watch "Writing to a text file" New topic

Writing to a text file

Brooke Maddox
Ranch Hand

Joined: Nov 23, 2012
Posts: 42
I am not sure if this is the correct forum, and I am very new to JSF so please bear with me.
I have a JSP page where a user can enter information which will then be written to a text file.
I have a class that has a method to write to the text file.
My problem ( I think ) is that I am not getting the right location of the text file and the path to it.
Here is the code of my class
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

You are attempting to write data into your WAR, using a relative path.

1. You should not attempt to use a relative path in J2EE apps. The current directory that the path is relative to is unpredictable and can be changed without notice.

2. You should NEVER attempt to write anything into a WAR or into any of the directories that your webserver live in. The WAR should be treated as read-only (sometimes it is), and even if you can write to it, any data written there may not stay written there.

It is better to select a directory that is external to your webserver and write your files into it.

An IDE is no substitute for an Intelligent Developer.
Brooke Maddox
Ranch Hand

Joined: Nov 23, 2012
Posts: 42
Thank you Tim :)
I agree. Here's the link:
subject: Writing to a text file
It's not a secret anymore!