The  SequeNce inputStream class allows  to concatenate multiple Input Streams. The construction of.a SequenceinputStream is different from any. other InputStream. A Sequence inputStream COnstructor uses either a pair of InputStream spr an  enumeration of putStrln as its argument:

Sequence InputStream(InputStream first, inputStream second)
Sequence InputStream (Enumeration Streaminput)

Operationally, the class fulfills read requests from the first InputStream until it runs out and the  swover to the second one. In the case of an Enumeration, it will continue ugh, all of the Input Streams until) the end of the last one is reached. Here is a Simple example that uses-a SequenceinputStream to the contents of two  files.

This example creates a Vector and then adds two filenames to it. It passes that vector of names to the InpurStreamfi numerator class, which is designed to provide a wrapper on the vector where the elements returned are not the filenames but rather open.

FileinputStream on those names. The Sequence input Stream opens each file in turn, and this example prints the contents of the two files.


The PrintStream class provides all of the formatting capabilities we have been using from the System file handle, System.out, since the beginning of the book. PrintStream has two constructors:

PrintStream(OutPutStream outputStream)
PrintStream(OutputStream outputstreani, booleanflusltOnNewline)

whereflusllOnNewlitlc.controls whether Java flushes the output stream every time a  newline (\n) character is output. IfflllshOnNewlitie is true, flushing' automatically takes  place If it is false; flushing is not automatic,.The first constructor does not  automatically flush.

The Printstream constructors were deprecated by Java 1.1because PrintStream do not handle Unicode characters and are thus not able to be conveniently internationalized, (For new code, you should use PrintWriter, which is described later IN this chapter However, the methods defined by PrintStream are not deprecated. This means that it is permissible to use a PrintStream but·not to create one! At first this seems absurd, but it isn't. The reason is that System.out is a PrintStream that is widely used, Since PrintStream methods aren't deprecated, it is still permissible to use System Out. However, for new programs, it is best to restrict your use of System.out to simple utilities, debugging, and example programs. Any real-world program that displays console output should do so through a PrintWriter
so that it can be used in the global environment.

Java's PrintStream objects support the print () and println( ) methods for all types, including Object, If an argument is not a simple type, the PrintStream methods will call the object's ( ) wetland and then print the result.

Share This