Java Input Output l l l a modular







- Slides: 7

Java Input / Output l l l 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: Console. App. java

Java Input / Output l l two class hierarchies… byte stream objects (8 bit bytes) • Java abstract classes: Input. Stream, Output. Stream l character/textual stream objects 16 bit UTF-16 characters • Java abstract classes: Reader, Writer

Week 11: Java Input / Output l l three predefined byte streams - System. in ( Input. Stream object ) - System. out ( Print. Stream object ) - System. err ( Print. Stream object ) Print. Stream: an Output. Stream object that contains print() and println()

The API for Java Input/Output l l 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 Input. Stream data sink streams File. Input. Stream Output. Stream Reader Writer File. Output. Stream File. Reader File. Writer processing streams Buffered. Input. Stream Buffered. Output. Stream Object. Input. Stream Object. Output. Stream Input. Stream. Reader ——————— Buffered. Reader Output. Stream. Writer ——-—— Buffered. Writer

Examples of Java I/O Applications l l keyboard input: Console. App. java - use of a byte stream and character streams file I/O - byte streams: File. Streams. java - character streams: File. Reader. Writer. java - formatted data and byte stream: Data. IOTest. java

Java I/O Applications l use of Properties file • externalize connection parameters • DBConnection. File. java l use of text file to store SQL • Create. DBFile. java