aspose file tools*
The moose likes I/O and Streams and the fly likes Unbuffered.... yes..... unbuffered output to a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Unbuffered.... yes..... unbuffered output to a file" Watch "Unbuffered.... yes..... unbuffered output to a file" New topic
Author

Unbuffered.... yes..... unbuffered output to a file

Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1613
    
  10

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:


Thanks!
Janeice


When you do things right, people won't be sure you've done anything at all.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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.


[Jess in Action][AskingGoodQuestions]
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1613
    
  10

Thanks for your reply....

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"......


Janeice
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

If this is a homework problem, I suspect as long as you're not using BufferedWriter/BufferedOutputStream, you're doing unbuffered output.
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1613
    
  10

Thanks! that solved my issues!!



--Janeice
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unbuffered.... yes..... unbuffered output to a file
 
Similar Threads
read/write
java.io.Exception: Insufficient system resources exist to complete the requested serv
Loading/Saving a Listbox
Can I have a response object content type = "null"?
Send a String to Server and server send it somewhere on network