Ok so this project for school has the following criteria:
1. read (unbuffered stream) from file A -- got it to work
2. write (unbuffered stream) to file B
3. read file B and write to file C (both buffered streams) -- I forsee no problem with this.
So when I try to write to file B, gradebook.txt, the first line (if I only do one) works. If I print more than one line I get a runtime error (string index out of bounds) and an empty file. When I println the output it's correct, so I'm pretty sure the problem is with my writing code. I think I'm in need of some syntax help.....
This is what I have:
When you do things right, people won't be sure you've done anything at all.
The second argument to write() is not the file position; it's the character position in the String argument to start at. If you're writing a series of Strings, then that argument will always be 0. And the other version of write() that takes just the String argument is a shortcut for write(string, 0, string.length()), so you might as well just write write(string) for each line.
I tried this for what I thought was the first time.... and now I remember why I used the long version of write (with the three parameters)....
The output I get in this case is one line. The last line entered. I wanted to set the position to start the writing AFTER (or I suppose insert it before.... if that were possible) the position the last one ended. Now that I understand what is meant by position, it makes perfect sense why I'm getting the runtime error.
Please let me know what you think...
.... as an addendum...... do you think if I used a stringbuffer to build the output then send it to the "writer" that it would be considered buffered writing? I've been tossing this idea around but I'm not sure what EXACTLY is meant by "unbuffered"......
author and iconoclast