sara wrote:
>
> I am trying to find out what is the different between DataInputStream, and
> BufferedInputStream classes of java.io, well what I understood after reading
> java.io doc is that BufferedInputStream helps to read data easier by
> obviously "buffering" it so the user will not lose any data due to the speed
> different? is that true?
Almoust. You will not loose data anyway (if your program is correct :)
Buffer helps in many ways. For example, data from disk can come in 1024
bytes. So, buffer will read 1024 in one time and then give for you 1024
times before next "physical" read.
> is this the main advantage of BufferedInputStream
> ?? how about BufferedOutStream? why do I need it.
For the same reason - speed.
BufferedInputstream is a middleware stream. Usually low level like
keyboard, or file, or URL connection (socket) exist as InputStream. Then
it is used for creating BufferedInputStream and then for something more
specific Reader (to translate and read charecters/unicode) or
DataInputStream (particular data like int, double, String...).
In logic it looks like
InputStream => BufferedInputStream => DataInputStream
In Java code it looks like
DataInputSteam DIS= new DataInputStream(new BufferedInputStream(
System.in )));
String input=DIS.readLine(); // Depricated
String input1=DIS.readUTF();
or
BufferedReader d = new BufferedReader(new BufferedInputStream((new
Socket("www.yahoo.com", 80)).getInputStream()));
String yahoo=d.readLine();
Last one is double buffering. It's for fun only. Try to understand that
you can construct any streams what you want! Everything will be good if
you understand concepts.
Masha Kizub.