Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing information to a file  RSS feed

 
Stacy Beery
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have wrote a basic class file with one method: displayInformation. I want to change this from displaying the information in the console to writing in into a basic text file. I know how to create a file, but struggling to get from the method to the file.

My method is a very simple println to the console:


My current filewriter:


So I think I have the basics down, but I am just unsure how to change my method or my filewriter in order to save the information to a file. I would like to just be able to pass the method through the filewriter, but I am sure that will not work. Just uncertain how to change it.
 
Campbell Ritchie
Sheriff
Posts: 54600
151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a Swing topic: moving to the BJ forum.

I suspect that your problem is at a much more basic level. You need to know about fields and local variables, and which information is available where in your object. Is the information you want to write fields of this object, or local variables, or method parameters? Each of those changes where the information exists at all.
The file writing looks all right. I would probably use a buffered writer instead of a print writer, but that won't make much difference. I would probably use try‑with‑resources, but you might not know enough exception handling to use that yet.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!