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,FileOutputStream
Note 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:
CharArrayReaderandCharArrayWriterByteArrayInputStreamandByteArrayOutputStream- 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.
FileReaderandFileWriterFileInputStreamandFileOutputStream- 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.PipedReaderandPipedWriterPipedInputStreamandPipedOutputStream- 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.StringReaderandStringWriterStringBufferInputStream- 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.
A java blog with a collection of examples and tutorials on Java and related technologies. (Under maintenance with continuous updates) Be in touch with java jazzle or k2java.blogspot.com.
Tuesday, May 10, 2011
Using the Data Sink Streams
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment