Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem saving data to text file correctly

 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When a user inputs data via a keyboard in the test main class, and subsequently saves this data to a text file, an extra space is added before the string data. The text file is saved in the following format,

Each subsequent addition and saving of data to the file, adds a further space before the string in the text file. Therefore, each time some data is added and saved to the text file, another space is also saved. I really don't see why this happening.

The code for the constructors in the video class is as follows

The method for saving the data to the text file is as follows,

The strange thing, is that when the data is saved to the text file, the addition of an extra space before the string does not affect the first and last line of the text file.

This is all rather puzzling at the moment. Any ideas or advice as to why this might be happening?
 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I don't know whether this helps or not, but the current code for my main class is as follows,

Can anybody see why this problem might be occurring?

Any help or advice appreciated!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a guess - see if the readline() that reads the last token on each line preserves the space in front of the word. You might be getting the extra space there.
 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply. Each time the data is saved to the text file, only the first and last lines are saved in the correct format. How would I check whether the readLine()is saving a space before the string on each line?

If it is saving the space before the string when saving the data, any ideas how I can remove or prevent this from happening?

It is all rather puzzling at the moment!
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we need to see the code for SimpleReader...
 
Ryan Zezeski
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea, the problem doesn't seem to be in the code you provided, seeing SimpleReader would help. Also does the number of spaces incrememnt for each line, or is it always one space at the beginning of the line?



Also, did you try using trim() ?
[ December 04, 2005: Message edited by: Ryan Zezeski ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic