java - When should we use BufferedInputStream,FileInputStream or DataInputStream? -


this question has answer here:

i'm confused above mentioned classes. when use what? perspective every thing comes in, in form of stream in java right? 1 use in case make input more efficient? answer please can use datainputstream or bufferedinputstream in case of reading content files?

fileinputstream

is used reading files.

see javadoc:

a fileinputstream obtains input bytes file in file system. files available depends on host environment. [...]

datainputstream

is used reading in primitive java types (that might have written using dataoutputstream) , provides convenience methods purpose, e.g. writeint().

see javadoc:

a data input stream lets application read primitive java data types underlying input stream in machine-independent way. [...]

bufferedinputstream

is used buffered block reads inputstream (instead of single bytes) , increases performance if reading small chunks of data. of time want use text processing.

see javadoc:

a bufferedinputstream adds functionality input stream-namely, ability buffer input[...].


of course can combine following decorator pattern.


example of writing primitive java types file:

fileoutputstream write = new fileoutputstream  dataoutputstream out = new dataoutputstream(write); out.writeint(10); write.close(); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -