|
|
Start of Tutorial > Start of Trail > Start of Lesson | Search |
Data sink streams read from or write to specialized data sinks such as strings, files, or pipes. Typically, for each reader or input stream intended to read from a specific kind of input source, java.io contains a parallel writer or output stream that can create it. The following table givesjava.io's data sink streams.
Sink Type Character Streams Byte Streams Memory CharArrayReader,
CharArrayWriterByteArrayInputStream,
ByteArrayOutputStreamStringReader,
StringWriterStringBufferInputStreamPipe PipedReader,
PipedWriterPipedInputStream,
PipedOutputStreamFile FileReader,
FileWriterFileInputStream,
FileOutputStreamNote that both the character stream group and the byte stream group contain parallel pairs of classes that operate on the same data sinks. These are described next:
CharArrayReaderandCharArrayWriter
ByteArrayInputStreamandByteArrayOutputStream- Use these streams to read from and write to memory. You create these streams on an existing array and then use the read and write methods to read from or write to the array.
FileReaderandFileWriter
FileInputStreamandFileOutputStream- Collectively called file streams, these streams are used to read from or write to a file on the native file system. How to Use File Streams has an example that uses
FileReaderandFileWriterto copy the contents of one file into another.PipedReaderandPipedWriter
PipedInputStreamandPipedOutputStream- Implement the input and output components of a pipe. Pipes are used to channel the output from one program (or thread) into the input of another. See
PipedReaderandPipedWriterin action in How to Use Pipe Streams.StringReaderandStringWriter
StringBufferInputStream- Use
StringReaderto read characters from aStringas it lives in memory. UseStringWriterto write to aString.StringWritercollects the characters written to it in aStringBuffer, which can then be converted to aString.StringBufferInputStreamis similar toStringReader, except that it reads bytes from aStringBuffer.
|
|
Start of Tutorial > Start of Trail > Start of Lesson | Search |