it needs java.io package containers .All these streams represent an input source and an output destination.
Stream:
A stream can be defined as a sequence of data there are two kinds of streams
InputStream:It is used to read data from a source
OutputSTream:It is used for writing data o a destination
Here is a hierarchy of classes to deal with Input and Output streams:
The two important streams are FileInputSTrea and FileOutputSTream which would be discussed in this tutorial:
Following constructor will create a input stream object to read the file:
InputStream foo=new InputSTream("C:/java/hello");
File f=new File("C:/java/hello"); InputStream f=new FileInputStream(f);
Once you have InputStream object in hand, then there is a list of helper methods which can be used to read to stream or to do other operations on the stream.
public void close() throws IOException{ }
public int available() throws IOException{ }
And there is OutPutStream that can be discussed later.It is almost same like:
And there are some other class for filereading and writing and creating directories.
Byte stream:
Character Streams:
Standard Streams:
Standard Input: System.in
Standard Output: System.out
Standard Error: System.err
Just like STDIN,STOUT,STDERR in C/C++
example to demonstrate inputstream and outputstream:
public class FileStreamTest { public static void main(String[] args) { try{ byte bWrite[]={11,21,3,40,5}; OutputStream os=new FileOutputStream(test.txt); for(int x=0; x<) //Not completed yet. } } }