1 / 20

IO in java

IO in java. Stream. Character Stream Byte Stream. Character & ByteStream classes. FileWriter FileReader. Buffered Character Stream. BufferedReader BufferedWriter By buffering, no. of reads and writes to the physical device is reduced. BufferedWriter.

amora
Download Presentation

IO in java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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, intbufsize) Methods: same as Writer void newLine() throwsIOException program

  7. BufferedReader • It buffers input from character stream. • Constructor: BufferedReader(Reader r) BufferedReader (Reader r, intbufsize) 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(OutputStreamos) PrintWriter(OutputStreamos,booleanflushOnNewline) PrintWriter(Writer w) PrintWriter(Writer w, os,booleanflushOnNewline)

  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(OutputStreamos)

  14. Methods • void writeInt(inti) • Void writeBoolean(Boolean b) • Void writeByte(Byte b) • Void writeChar(inti) • 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() • booleanreadBoolean • char readChar() • double readDouble() • float readFloat() • long readLong() • short readShort() • intreadInt() • string readUTF() • Program

  17. BufferedOutputStream • Buffers output to a byte stream. • Constructor: BufferedOutputStream(OutputStreamos) BufferedOutputStream(OutputStreamos, intbufSize) Program:

  18. BufferedInputStream • Buffers input from a byte stream. • Constructor: BufferedInputStream(InputStream is) BufferedInputStream(InputStream is, intbufSize) 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) • intskipByte(int n)

More Related