I have a method. The problem is that it copies last few ending lines to the end of outputfile. Any solution?
if I use byte array of size 10, I get it correctly ie file is written correctly, but I don't know whether it will behave appropriately in all situations. Is there any benefit over using bis.read() and bos.write() ie the methods that read/ write a single int. Thanks in Advance,
Maki Jav [ November 07, 2005: Message edited by: Maki Jav ]
First, bis.available() doesn't do what you think it does:
public int available() throws IOException
Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.
java.io.InputStream It does not return the number of bytes left to read in a stream. Have a look at the IO Chapter in Java Platform Performance to get an idea as to how to best use the various IO classes.
This will not always work correctly! Read the API documentation of the methods carefully.
fis.read(readBytes) is not required to read exactly as many bytes as fit in the buffer. It may also read less than that. You need to take the return value into account, which is the number of bytes that it really read.