




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lecture was delivered by Aniruddh Parmar at B. R. Ambedkar Bihar University for Data Transfer Programming course. It includes: Streams, Ordered, Sequence, Data, Input, Output, Destination, Abstraction, Transfer, Connections, Algorithm, Character
Typology: Slides
1 / 28
This page cannot be seen from the preview
Don't miss anything!





















bytes 010011001 010011001 bytes
Character Streams (^) Byte Streams
Byte Streams
Data Streams
Character Streams (^) Byte Streams Data Sink Streams Processing Streams
I/O Super Classes
int write( int c); int write( char cbuf[]); int write( char cbuf[], int offset, int length)
int write(byte b); int write( byte buffer[]); int write( byte buffer[], int offset, int length)
Using File Streams import java.io.*; public class Copy { public static void main(String[] args) throws IOException { File sf = new File(“src.txt"); File of = new File("out.txt"); FileReader in = new FileReader(sf); FileWriter out = new FileWriter(of); int c; while ((c = in.read()) != -1) { out.write(c); } in.close(); out.close(); } } FileReader FileWriter in out
Using String Streams class Capitalize { public static void main(String[] args) { Reader in = new StringReader (“advance programming”); Writer out = new StringWriter(10); int nextChar = 0; while ((nextChar = in.read()) != -1) { out.write(Character.toUpperCase (( char )nextChar)); } System.out.println(out.toString()); in.close(); out.close(); } } ADVANCE PRGRAMMING
Reverse Sort Reverse Reverse Sort Reverse
Buffer Streams
Character Streams
Byte Streams
import java.io.*; public class Copy { public static void main(String[] args) throws IOException { // opening the streams FileReader in = new FileReader (“infile.txt"); BufferedReader br = new BufferedReader(in); FileWriter out = new FileWriter ("outfile.txt"); BufferedWriter bw = new BufferedWriter(out); // processing the streams String aLine = null ; while ((aLine = br.readLine()) != null ) { bw.write(aLine, 0, aLine.length()); } // closing the streams in.close(); out.close(); } }
Using Filter Streams DataInputStream & DataOutputStreams read and write primitive type (ints, floats, string etc.)
// write the data out DataOutputStream out = new DataOutputStream(new FileOutputStream("invoice1.txt")); for ( int i = 0; i < prices.length; i ++) { out.writeDouble(prices[i]); out.writeChar('\t'); out.writeInt(units[i]); out.writeChar ('\t'); out.writeChars (descs[i]); out.writeChar('\n'); } out.close(); double price; int unit; StringBuffer desc; double total = 0.0; // read it in again DataInputStream in = new DataInputStream( new FileInputStream("invoice.txt"));