How to explain this?
My bfin.read() reads bytes much less than assigned 4096?
FileInputStream fis = new FileInputStream(fileFrom);
bfin = new BufferedInputStream(fis,4096);
while (true) {
if ( (nbytes = bfin.read()) == -1) break;
System.out.println("nbytes: " + nbytes );
}
Here is the output:
...
nbytes: 117
nbytes: 56
nbytes: 15
nbytes: 134
nbytes: 41
nbytes: 69
nbytes: 176
nbytes: 60
nbytes: 21
nbytes: 9
nbytes: 198
nbytes: 242
nbytes: 166
nbytes: 56
nbytes: 119
nbytes: 52
nbytes: 101
nbytes: 38
nbytes: 203
...
Thanks
[694 byte] By [
learnj1] at [2007-9-26 3:25:22]

The BufferedInputStream.read() method you're using reads the next single byte from the stream and returns it as the function value. Try this instead: FileInputStream fis = new FileInputStream(fileFrom);
bfin = new BufferedInputStream(fis,4096);
byte[] buf = new byte[4096] ;
int nbytes ;
while (true) {
if ( (nbytes = bfin.read(buf)) < 0) break ;
System.out.println("nbytes: " + nbytes );
}
Hi, DragonMan if we add byte[] buf = new byte[4096], what is it (the other 4096) for inside bfin = new BufferedInputStream(fis,4096) ?Thnx