Professional Documents
Culture Documents
DEPARTMENT : CSE
Bachelor of Engineering (Computer Science & Engineering)
Java Programing(CST-205)
TOPIC OF PRESENTATION:
2
Introduction to Streams
• Java programs perform I/O through streams. A stream is:
– an abstraction that either produces or consumes information
– linked to a physical device by the Java I/O system
• All streams behave similarly, even if the actual physical devices to which they are
linked differ.
• Thus the same I/O classes can be applied to any kind of device as they abstract the
difference between different I/O devices.
• Java’s stream classes are defined in the java.io package.
• Java 2 defines two types of streams:
– byte streams
– character streams
• Byte streams:
– provide a convenient means for handling input and output of bytes
– are used for reading or writing binary data
• Character streams:
– provide a convenient means for handling input and output of characters
– use Unicode, and, therefore, can be internationalized
Predefined Streams
Column A Column B
13
FileOutputStream class methods
14
Example
Java FileOutputStream Example 1: write byte
import java.io.FileOutputStream;
public class FileOutputStreamExample {
public static void main(String args[]){
try{
FileOutputStream fout=new FileOutputStream("D:\\testout.txt");
Output:
fout.write(65);
Success...
fout.close();
The content of a text file testout.txt is set
System.out.println("success...");
with the data A.
}catch(Exception e){System.out.println(e);}
testout.txt
}
A
}
15
Summary:
Video Lectures :
https://youtu.be/lYuj9nn0PBU
Reference Links:
https://docs.oracle.com/javase/7/docs/api/java/io/FileOutputStream.html
https://www.tutorialspoint.com/java/io/index.htm
https://www.tutorialspoint.com/java/io/java_io_fileoutputstream.htm
https://www.javatpoint.com/java-io
https://www.javatpoint.com/java-fileoutputstream-class
THANK YOU