• Post Reply Bookmark Topic Watch Topic
  • New Topic

FileWrite Problem  RSS feed

 
Ryan Alfeche
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem with my code the output of the program is correct. but the output in the text file is having a problem.. Could anyone help me.. here is my code..

reverse_input.txt


reverse_output.txt


This is my code..



Sorry for my english
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If only the last line is showing up, then probably you're creating a new FileWriter for each line, which, by default, overwrites the existing file starting at the beginning. There are two solutions to this:

1) Create one FileWriter at the beginning and use it througout. (Close it in a finally block when you're done, of course.)

2) Create each FileWriter in append mode.

I would prefer #1 over #2 if I were doing it.
 
Ryan Alfeche
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:If only the last line is showing up, then probably you're creating a new FileWriter for each line, which, by default, overwrites the existing file starting at the beginning. There are two solutions to this:

1) Create one FileWriter at the beginning and use it througout. (Close it in a finally block when you're done, of course.)

2) Create each FileWriter in append mode.

I would prefer #1 over #2 if I were doing it.


@Jeff.

Thanks for the quick reply, it gives me idea on how to resolve my problem. and i figure it out now.. my text output is okay now.. thank you so much..

reverse_output.txt
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!