Lesson 5 | Other sources of input and output streams |
Objective | Investigate input and output streams from files, network connections, and programs. |
Input and Output Streams in Java
Besides System.in
and System.out
, the other sources of data in a Java program include files, network connections, and other programs. These other data sources are also provided as input or output streams.
Files
FileInputStream and FileOutputStream
Network connections
Network connections are also a fertile source of streams.
When you connect to an Internet server, you read the data the server sends you via an input stream, and you send data back to the server via an output stream.
Java Programs
Java programs themselves produce streams.
- ByteArrayInputStreams
- ByteArrayOutputStreams
- StringBufferInputStreams
- PipedInputStreams, and
- PipedOutputStreams
all use the stream metaphor to move data from one part of a Java program to another.
Network connections
Network connections are also a fertile source of streams. When you connect to an Internet server, you read the data the server sends you via an input stream, and you send data back to the server via an output stream.