• Post Reply Bookmark Topic Watch Topic
  • New Topic

Filewriter Problem  RSS feed

 
John Downs
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all. I am having an issue with using FileWriter to print some text to a text file. In the following code, I am supposed to be able to print the inital attributes and the user changed inputs into a file but all I am getting is the memory locations of the objects I created in one long line. Any help with this is greatly appreciated.

 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you creating the file? you should find more details in the Java Tutorials.
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where have you looked for the file?
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean you are getting this sort of thing?
project3final.Project3Final$Instrument@55f96302


project3final.Project3Final$Instrument@55f96302
That is what you get if you don't override the toString method.
 
John Downs
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Do you mean you are getting this sort of thing?
project3final.Project3Final$Instrument@55f96302


project3final.Project3Final$Instrument@55f96302
That is what you get if you don't override the toString method.


Yes this is what I'm getting. I asked about the Override method to my instructor and he said not to use it. Am I missing something?
 
John Downs
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:How are you creating the file? You should find more details in the Java Tutorials.


The file is created in my writeData method (or so I thought).
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Downs wrote: . . . I asked about the Override method to my instructor and he said not to use it. Am I missing something?
You must have misunderstood something very severely. You should override toString in just about every class you write. Had you overridden toString in the Instrument class, you would have something sensible in your file. If it is not quite to your likings, you can tweak toString.

If you were told not to use the @Override annotation, I would disagree there.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!