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?
Joined: Nov 06, 2005
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?
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.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Nov 06, 2005
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?
I think we need to see the code for SimpleReader...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
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 ]
Java has 99 problems but a pointer ain't one
subject: Problem saving data to text file correctly