Presentation is loading. Please wait.

Presentation is loading. Please wait.

IO in java.

Similar presentations


Presentation on theme: "IO in java."— Presentation transcript:

1 IO in java

2 Stream Character Stream Byte Stream

3 Character & ByteStream classes

4 FileWriter FileReader

5 Buffered Character Stream
BufferedReader BufferedWriter By buffering, no. of reads and writes to the physical device is reduced.

6 BufferedWriter It buffers output to a character stream. Constructor:
BufferedWriter(Writer w) BufferedWriter(Writer w, int bufsize) Methods: same as Writer void newLine() throwsIOException program

7 BufferedReader It buffers input from character stream. Constructor:
BufferedReader(Reader r) BufferedReader (Reader r, int bufsize) Methods: same as Reader void readLine() throwsIOException program

8 PrintWriter It displays string equivalents of simple type such as int, float, char, etc.. Constructor: PrintWriter(OutputStream os) PrintWriter(OutputStream os,boolean flushOnNewline) PrintWriter(Writer w) PrintWriter(Writer w, os,boolean flushOnNewline)

9 Methods: print() println() program:

10 ByteStream OutputStream and InputStream class has same methods as FileWriter and FileReader.

11 FileOutputStream It allows you to write binary data to a file.
Constructor: FileOutputStream(String filePath) throws IOException FileOutputStream(File obj) throws IOException Program

12 FileInputStream It allows you to read binary data from a file.
Constructor: FileInputStream(String filePath) throws FileNotFoundException FileInputStream(File obj) throws FileNotFoundException Program

13 DataOutputstream Class
It allows to write simple java types to byte output stream. Constructor: DataOutputStream(OutputStream os)

14 Methods void writeInt(int i) Void writeBoolean(Boolean b)
Void writeByte(Byte b) Void writeChar(int i) Void writeDouble(double d) Void writeFloat(float f) Void writeLong(long l) Void writeShort(short s) Void writeUTF(String s) Program

15 DataInputStream It allows to read simple java types from byte input stream. Constructor: DataInputStream(InputStream is)

16 Methods byte readByte() boolean readBoolean char readChar()
double readDouble() float readFloat() long readLong() short readShort() int readInt() string readUTF() Program

17 BufferedOutputStream
Buffers output to a byte stream. Constructor: BufferedOutputStream(OutputStream os) BufferedOutputStream(OutputStream os, int bufSize) Program:

18 BufferedInputStream Buffers input from a byte stream. Constructor:
BufferedInputStream(InputStream is) BufferedInputStream(InputStream is, int bufSize) Program:

19 Random Access File Previous classes only use sequential access to read and write to a file. This class allows to write programs that can seek to any location in a file to read & write data to that point. Constructor: RandomAccessFile(String filenm, String mode)

20 Methods void close() long length() int read()
int read(byte buffer[],int index, int size) void seek(long n) int skipByte(int n)


Download ppt "IO in java."

Similar presentations


Ads by Google