Java Files and I/O

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:
Java I/O StreamsThe 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.
	}
}
}

 

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *