J2EEOnline
GofPatterns OOPortal
prev next prev next
  Course navigation
 
Lesson 5
Objective
Other sources of input and output streams
Investigate input and output streams from files, network connections, and programs.
 
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
Files, whatever their contents, are read and written through input and output streams.
The java.io.FileInputStream class is used to read a file. The java.io.FileOutputStream class is used to write a file.
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.
  1. ByteArrayInputStreams
  2. ByteArrayOutputStreams
  3. StringBufferInputStreams
  4. PipedInputStreams, and
  5. PipedOutputStreams
all use the stream metaphor to move data from one part of a Java program to another.
  Course navigation