Sunday, June 15, 2014

What are FileInputStream and FileOutputStream

FileInputStream : It contains the input byte from a file and implements an input stream.
FileOutputStream : It uses for writing data to a file and also implements an output stream.

FileInputStream, FileOutputStream

byte[] bucket = new Byte[16];
x = is.read(bucket);
os.write(bucket, 0, x);

close close

public class FileHandling {
public static void main(String [ ] args) throws IOException
{
FileInputStream inputStream = new FileInputStream ("Input.txt") ;
FileOutputStream outputStream = new FileOutputStream("Output.txt",true) ;

byte[] buffer = new byte[1024];
//For larger files we specify a buffer size which defines the chunks size for data
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1)
        outputStream.write(buffer, 0, bytesRead);
inputStream.close() ;
outputStream.close() ;
}
}

No comments:

Post a Comment