Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Java IO System Different kinds of IO Different kinds of operations

Similar presentations


Presentation on theme: "The Java IO System Different kinds of IO Different kinds of operations"— Presentation transcript:

1 The Java IO System Different kinds of IO Different kinds of operations
Files, blocks of memory, network connections Different kinds of operations Sequential, random-access, binary, character, by lines, by words, etc.

2 Typical Uses of IO System
Reading and writing files Manipulating blocks of memory Network Programming

3 Streams, Readers & Writers
Java’s stream, reader, and writer classes view input and output as ordered sequences of bytes. Dealing strictly with bytes would be tremendously bothersome (data appears as bytes, or ints, or floats and so on) So we need low-level stream and high-level stream.

4 Low-level Streams Low-level output stream receives bytes and writes bytes to an output device. Low-level input stream read bytes from an input device and returns bytes to its caller. Example: FileInputStream & FileOutputStream ByteArrayInputStream & ByteArrayOutputStream

5 High-level Streams A high-level output stream receives general-format data, (ex: primitives), and writes bytes to: a low-level output stream , or another high-level output stream A high-level input stream reads bytes from: a low-level input stream, or another high-level input stream and returns general format data to its caller

6 High-level Streams Examples: DataInputStream & DataOutputStream
BufferedInputStream & BufferedOutputStream

7 High-level & Low-level Streams
DataOutputStream DataInputStream FileOutputStream FileInputStream writeByte() readByte() writeInt() readInt() readUTF() writeUTF() file Etc... Etc…. BufferedOutputStream BufferedInputStream

8 High-level & Low-level Streams
Example: FileOutputStream fo = new FileOutputStream (“my.data”); BufferedOutputStream bo = new BufferedOutputStream (fo); DataOutputStream do = new DataOutputStream (bo); do.writeChar (‘A’); do.writeInt (32.5);

9 Reader and Writer Classes
Internationalization: uses 16-bit char instead of 8-bit byte Also designed to improve speed Sometimes they can replace InputStream and OutputStream

10 Low-level Readers & Writers
FileReader & FileWriter CharArrayReader & CharArrayWriter StringReader & StringWriter etc….

11 High-level Readers & Writers
BufferedReader & BufferedWriter InputStreamReader & OutputStreamWriter LineNumberReader PrintWriter etc….

12 Readers and Writers PrintWriter OutputStreamWriter FileOutputStream
Text File BufferedWriter

13 Readers and Writers PrintWriter out = new PrintWriter(
new BufferedWriter( new OutputStreamWriter( new FileOutputStream (“TextFile”)))); out.println(str);


Download ppt "The Java IO System Different kinds of IO Different kinds of operations"

Similar presentations


Ads by Google