A stream is a flowing sequence of characters.
A program can get input by reading characters from a stream attached to a source.
A program can produce output by writing characters to a stream attached to a destination.
Input and output sources can be anything that can contain data: a file, a string, or memory.
standard input: InputStream System.in
standard output: PrintStream System.out
standard error: PrintStream System.err
Read data from or write data to a file on the native file system.
Read data from or write data to a byte array in memory.
Allow programs to read from a StringBuffer as if it were an input stream.
To use a filtered input (output) stream, you attach the filtered stream to another input (output) stream:
DataInputStream dis = new DataInputStream(System.in.read());
String input;
while ((input = dis.readLine()) != null) {
. . . // do something interesting here }DataInputStream and DataOutputStream
BufferedInputStream and BufferedOutputStream
LineNumberInputStream
PushbackInputStream
Byte pushback buffer
PrintStream
File inputFile = new File("farrago.txt");
File outputFile = new File("outagain.txt");
FileInputStream fis = new FileInputStream(inputFile);
FileOutputStream fos = new FileOutputStream(outputFile);
while ((c = fis.read()) != -1) {
fos.write(c);
}
fis.close();
fos.close();Copyright © 1998-2009 Dilvan Moreira