Java InputStream -


i reading tutorial using i/o streams in java , stumbled upon following code inputstream:

    inputstream input = new fileinputstream("c:\\data\\input-file.txt");     int data = input.read();      while(data != -1){     data = input.read();      } 

the tutorial mentions inputstream returns 1 byte @ time. if want receive more bytes @ time, possible using different method call?

use read(byte[]) overload of read() method. try following:

byte[] buffer = new byte[1024]; int bytes_read = 0; while((bytes_read=input.read(buffer))!= -1) { // read bytes here } 

further can channel inputstream datainputstream more specific tasks reading integers, doubles, strings etc.

datainputstream dis=new datainputstream(input); dis.readint(); dis.readutf(); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -