0% found this document useful (0 votes)
195 views9 pages

Java I/O Streams Java I/O Streams Java I/O Streams Java I/O Streams

Java uses streams to represent ordered sequences of data flowing between devices and programs. Streams provide a standard way to read and write data sequentially. There are predefined input and output streams in Java like System.in for keyboard input and System.out for console output. The BufferedReader class is used to efficiently read text from character streams and supports reading lines of input. It uses an internal buffer to improve performance over lower-level streams.

Uploaded by

jmeenzes
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
195 views9 pages

Java I/O Streams Java I/O Streams Java I/O Streams Java I/O Streams

Java uses streams to represent ordered sequences of data flowing between devices and programs. Streams provide a standard way to read and write data sequentially. There are predefined input and output streams in Java like System.in for keyboard input and System.out for console output. The BufferedReader class is used to efficiently read text from character streams and supports reading lines of input. It uses an internal buffer to improve performance over lower-level streams.

Uploaded by

jmeenzes
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 9

Java I/O Streams

Streams
Java Uses the concept of Streams to represent the ordered sequence of data, data a common characteristic shared by all I/O devices. A stream in Java is a path along which data flows (like a river or pipe along which water flows).

Streams
To read data, a JAVA program opens a stream on a source (such as a file, memory, or a socket) file memory It then reads the information sequentially To T send information to an external destination, di f ti t t l d ti ti the program opens a stream to the destination and writes the data sequentially to the stream d it th d t ti ll t th t Java has predefined byte streams:
System.in System.out System.err

keyboard standard input stream CPU standard d d output stream MEM

monitor terminal console

HDD

keyboard standard input stream CPU standard d d output stream file input stream t LOAD READ MEM

monitor terminal console

HDD files file output stream SAVE WRITE

BufferedReader Class
This class is used to read text from a charactercharacterp , g input stream, buffering characters so as to provide efficient reading of characters, arrays, and lines. The most commonly used constructor for BufferedReader object is: BufferedReader input = new BufferedReader(READER); BufferedReader(READER);
where input is the name of the BufferedReader object

BufferedReader Class
READER is any Reader object. The commonly used ones are To input from keyboard new InputStreamReader(System.in) InputStreamReader(System.in) To input from file new FileReader(filename); FileReader(filename); Data i D is read from the B ff dR d using the df h BufferedReader i h readLine() readLine() method which returns a string until an E Enter (newline character) is encountered. ( li h )i d

In the following example, the keyboard sends data to the InputStream(System.in) which is InputStream(System.in) connected to a InputStreamReader stream which is connected to a BufferedReader stream. The data are transformed along the way. The raw bytes from the keyboard are grouped together into a String object that the program reads using stdin.readLine(). stdin.readLine().

Using Streams

References
Lesson: Basic I/O (The Java Tutorials > Essential Classes) http://java.sun.com/docs/books/tutorial/essential/io/index.ht ml CHAPTER 82 Input and Output Streams http://chortle.ccsu.edu/java5/Notes/chap82/ch82_1.html htt // h tl d /j 5/N t / h 82/ h82 1 ht l Chapter 13 Using Java Streams http://docs.rinet.ru/WebJPP/ch13.htm#WhatIsaStream http://docs rinet ru/WebJPP/ch13 htm#WhatIsaStream Chapter 4 I/O Streams, Java Network Programming by E.R. Harold, OReilly

You might also like