21-02-25 ---------- Q)What is stream in Java? =>A stream is a data transferring object . =>A stream transfers data into the Java program from an external source and from the Java program to a destination. Q)How are streams classified? =>Based on the direction of flow of data, streams are of two types. 1.)input streams 2.)output streams =>input streams bring data into the Java program. =>Output streams transfer data out of the Java program to a destination. =>Based on the type of data being transferred, streams are of two types. 1)character oriented streams (transfer textual data) 2)byte streams/binary streams (transfer binary data for eg. images) Q)How to perform an I/O operation in a Java program? Step 1:- Create an appropriate stream object. (In java.io package, stream classes are given) Step 2:- Write data into the stream OR read data from the stream. Step 3:- close the stream once done with the I/O operation Q)Write a Java program that stores some text into a disk file. //StoringIntoFile.java import java.io.FileWriter;//character oriented output stream class import java.io.IOException; class StoringIntoFile{ public static void main(String[] args) throws IOException{ FileWriter fileWriter=new FileWriter("one.txt"); fileWriter.write("storing data into a text file"); fileWriter.close(); System.out.println("data stored into the text file"); }//main }//class Q)Write a Java program that retrieves data from a text file and displays on the monitor. import java.io.FileReader;//character oriented input stream class import java.io.IOException; class ReadingFromFile{ public static void main(String[] args) throws IOException { FileReader fileReader=new FileReader("one.txt");//stroing data into the file int c=fileReader.read(); while(c !=-1){ System.out.print((char)c); c=fileReader.read(); } fileReader.close(); }//main }//class