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

save information to a text file  RSS feed

 
rashed khan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a JFrame where the user enters their details, I now need to save these details into a text file. Can anyone send me some sample code or point me to the right direction??? Your help would be much appreciated
Thanks
 
Joe Ess
Bartender
Posts: 9428
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch.
The Java Tutorial chapter on Basic IO is a good starting place.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BufferedWriter a = new BufferedWriter(new FileWriter(new File("info.txt")));

and then you can do
a.write(textbox.getText());
and
a.newLine();


but you have to do this in a try/catch statement

try{ // the above } catch (Exception e){System.out.println("no file"); }

Justin
 
Paul Clapham
Sheriff
Posts: 22480
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Justin Fox:
a.write(textbox.getText());
and
a.newLine();
Or more directly:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!