wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes FileInputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "FileInputStream" Watch "FileInputStream" New topic


Lakshmi Grandhi

Joined: Jan 31, 2002
Posts: 5
I cannot understand how inputstream fills array.
(filling array means writing , is not it right)
byte b;
byte bytes[] = new byte[100];
byte morebytes[] = new byte[50];
FileInputStream fis = new FileInputStream('fname");
b= (byte) fis.read(); //Single byte
fis.read(bytes); // fill the array
fis.read(morebytes, 0, 20); // 1st 20 elements
catch(IOException e){}
I cannot understand, please explain it me.
Thanks in advance.
mark stone
Ranch Hand

Joined: Dec 18, 2001
Posts: 417
yes, filling an array means writing into the given array.
the read method is overloaded here and you have also taken the 3 examples for the read method. Note how its arguments vary, first one does not have any argument, second one takes one argument and the third one takes 3 arguments.
fis.read(b);// this would read x bytes from the file (fname) and fill the array b[] with it. where x = b.length
why don't you make a file called as fname and then see for yourself how and what are the contents of the array b[] are....
hint: System.out.println(b[0]+" "+b[1) ...etc)
i hope you got the point.
It is sorta covered in the JavaRanch Style Guide.
subject: FileInputStream
It's not a secret anymore!