FILES STREAMS
SYNOPSIS:
 FILES
 STREAM
 INPUT STREAM
 OUTPUT STREAM
 SEREALIZATION
FILES:
 It is a collection of data
 In which collection of informations are
stored.
STREAM:
 A stream is a sequence of data. In Java, a
stream is composed of bytes. It's called a
stream because it is like a stream of water
that continues to flow.
Cntd….
In Java, 3 streams are created for us
automatically. All these streams are attached with
the console.
1) System.out : standard output stream
2) System.in: standard input stream
3) System.err : standard error stream
TYPES OF STREAMS:
There are two types of streams:
1. Input Stream – It reads data from the
source.
2. Output Stream – It writes data to the
destination.
INPUT STREAM
 Input Stream class is the superclass of all the
io classes i.e. representing an input stream
of bytes. It represents input stream of bytes.
Applications that are defining subclass of
Input Stream must provide method, returning
the next byte of input.
A reset() method is invoked which re-
positions the stream to the recently marked
position.
EXAMPLE
import java.io.FileInputStream;
public class DataStreamExample {
public static void main(String args[]){
try{
FileInputStream fin=new FileInputStream("D:testout.txt
");
int i=fin.read();
System.out.print((char)i);
fin.close();
}catch(Exception e){System.out.println(e);}
}
}
OUTPUT STREAM
 This abstract class is the superclass of all
classes representing an output stream of
bytes. An output stream accepts output bytes
and sends them to some sink.
Applications that need to define a subclass of
OutputStream must always provide at least a
method that writes one byte of output.
EXAMPLE
import java.io.*;
class OutputStreamDemo
{
public static void main(String args[])throws Exception
{
OutputStream os = new FileOutputStream("file.txt");
byte b[] = {65, 66, 67, 68, 69, 70};
os.write(b);
os.flush();
for (int i = 71; i <75 ; i++)
{
os.write(i);
}
os.flush();
os.close();
}
}
RANDOM ACCESS FILE:
 Files in which records can be accessed
in any order.it is also called direct
access file.
SERIEALIZATION:
 Serialization is a mechanism of converting
the state of an object into a byte stream.

Files streams..

  • 1.
  • 2.
    SYNOPSIS:  FILES  STREAM INPUT STREAM  OUTPUT STREAM  SEREALIZATION
  • 3.
    FILES:  It isa collection of data  In which collection of informations are stored.
  • 4.
    STREAM:  A streamis a sequence of data. In Java, a stream is composed of bytes. It's called a stream because it is like a stream of water that continues to flow.
  • 5.
    Cntd…. In Java, 3streams are created for us automatically. All these streams are attached with the console. 1) System.out : standard output stream 2) System.in: standard input stream 3) System.err : standard error stream
  • 6.
    TYPES OF STREAMS: Thereare two types of streams: 1. Input Stream – It reads data from the source. 2. Output Stream – It writes data to the destination.
  • 7.
    INPUT STREAM  InputStream class is the superclass of all the io classes i.e. representing an input stream of bytes. It represents input stream of bytes. Applications that are defining subclass of Input Stream must provide method, returning the next byte of input. A reset() method is invoked which re- positions the stream to the recently marked position.
  • 8.
    EXAMPLE import java.io.FileInputStream; public classDataStreamExample { public static void main(String args[]){ try{ FileInputStream fin=new FileInputStream("D:testout.txt "); int i=fin.read(); System.out.print((char)i); fin.close(); }catch(Exception e){System.out.println(e);} } }
  • 9.
    OUTPUT STREAM  Thisabstract class is the superclass of all classes representing an output stream of bytes. An output stream accepts output bytes and sends them to some sink. Applications that need to define a subclass of OutputStream must always provide at least a method that writes one byte of output.
  • 10.
    EXAMPLE import java.io.*; class OutputStreamDemo { publicstatic void main(String args[])throws Exception { OutputStream os = new FileOutputStream("file.txt"); byte b[] = {65, 66, 67, 68, 69, 70}; os.write(b); os.flush(); for (int i = 71; i <75 ; i++) { os.write(i); } os.flush(); os.close(); } }
  • 11.
    RANDOM ACCESS FILE: Files in which records can be accessed in any order.it is also called direct access file.
  • 12.
    SERIEALIZATION:  Serialization isa mechanism of converting the state of an object into a byte stream.