System.out
is an OutputStream
; specifically it's a PrintStream
. There's a corresponding System.in
which is an InputStream
used to read data from the console.
Data for streams can also come from files. Later you'll see how to use the File
class and the FileInputStream
and FileOutputStream
classes to read and write data from files.
Network connections commonly provide streams. We'll talk about this in a couple of weeks.When you connect to a web or ftp or some other kind of server, you read the data it sends from an InputStream
connected from that server and write data onto an OutputStream
connected to that server.
Java programs themselves produce streams. ByteArrayInputStream
s, ByteArrayOutputStream
s, StringBufferInputStream
s, PipedInputStream
s, and PipedOutputStrea
ms all use the stream metaphor to move data from one part of a Java program to another.
Perhaps a little surprisingly, components like TextArea
do not produce streams.
However you can always use the strings they do produce to create a ByteArrayInputStream
or a StringBufferInputStream
.