Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

FileInputStream

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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];
try{
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
fis.close();
}
catch(IOException e){}
I cannot understand, please explain it me.
Thanks in advance.
 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
example
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.
 
grapes are vegan food pellets. Eat this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic