110 likes | 280 Views
Java Input / Output. a modular approach to input/output: - different stream objects are connected/wrapped to handle I/O a data stream object: a flow of data an input stream: an object used for reading data an output stream: an object used for writing data
E N D
Java Input / Output • a modular approach to input/output: - different stream objects are connected/wrapped to handle I/O • a data stream object: a flow of data • an input stream: an object used for reading data • an output stream: an object used for writing data • Example: ConsoleApp.java
Java Input / Output • two class hierarchies… • byte stream objects (8 bit bytes) • Java abstract classes: InputStream, OutputStream • character/textual stream objects16 bit UTF-16 characters • Java abstract classes: Reader, Writer
Week 11: Java Input / Output • three predefined byte streams - System.in ( InputStream object ) - System.out ( PrintStream object ) - System.err ( PrintStream object ) • PrintStream: an OutputStream object that contains print() and println()
The API for Java Input/Output • functional categories of I/O classes • data sink streams: objects that read from and write to data “sinks” (i.e. sources and destinations) • processing streams: objects that process the data (e.g. data conversion, buffering) • processing streams offer efficient reading, writing and functionality
The API for Java Input/Output InputStream OutputStream Reader Writer data sink streams FileInputStream FileOutputStream FileReader FileWriter processing streams BufferedInputStream BufferedOutputStream ObjectInputStream ObjectOutputStream InputStreamReader ——————— BufferedReader OutputStreamWriter ——-—— BufferedWriter
Examples of Java I/O Applications • keyboard input: ConsoleApp.java - use of a byte stream and character streams • file I/O - byte streams: FileStreams.java - character streams: FileReaderWriter.java - formatted data and byte stream: DataIOTest.java
Java I/O Applications • use of Properties file • externalize connection parameters • DBConnectionFile.java • use of text file to store SQL • CreateDBFile.java