Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem writing to text file  RSS feed

 
David McHugh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i want to write a form value into a text file, i have a simple class below, the value gets written to the page, no exception gets thrown either, just no information gets entered into the file, i have tried using just a normal text string and run the program from the cl and that works fine, but when i try and use it through a form nothing happens.


 
Roland Maurer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this code works for me !
I believe your value "request.getParameter("message")" is a string with zero lengths


String text = "hello";
File file = new File("text.txt");
BufferedWriter output = new BufferedWriter(new FileWriter(file));
output.write(text);
output.close();



#
Originally posted by David McHugh:
hi,

i want to write a form value into a text file, i have a simple class below, the value gets written to the page, no exception gets thrown either, just no information gets entered into the file, i have tried using just a normal text string and run the program from the cl and that works fine, but when i try and use it through a form nothing happens.


 
Roland Maurer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for posting the previous msg again (:
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the file created? Or not even that?
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you looking for the file?
You should be aware that a relative file path (as opposed to an absolute path which completely specifies a location) will be resolved from the current user directory (see java.io.File for details). The "current" directory when running an application server will probably be the directory you started the server from.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!