Java SequenceInputStream ClassLast Updated : 23 Jan 2026 The SequenceInputStream class in Java is used to read data sequentially from multiple input streams as if they were a single stream. In this chapter, we will learn what the SequenceInputStream class is, its declaration, constructors, methods, and how to read data from multiple files using different examples. What is SequenceInputStream in Java?The SequenceInputStream class is used to read data from two or more input streams one after another. It reads the data from the first stream completely and then continues reading from the next stream. This class is useful when data is divided into multiple files and needs to be read in a continuous sequence. SequenceInputStream Class DeclarationThe following declaration shows how the SequenceInputStream class is defined: Constructors of SequenceInputStream ClassThe SequenceInputStream class provides constructors to read data from multiple input streams. 1. SequenceInputStream(InputStream s1, InputStream s2)This constructor creates a new input stream that reads data first from s1 and then from s2. Syntax: Here is the syntax of this constructor: 2. SequenceInputStream(Enumeration e)This constructor creates a new input stream that reads data from multiple input streams provided through an Enumeration. Syntax: Here is the syntax of this constructor: Methods of SequenceInputStream ClassThe SequenceInputStream class provides methods to read data from combined streams.
Examples of SequenceInputStream ClassThe following examples demonstrate how to use the SequenceInputStream class in different scenarios. Example 1: Reading Data from Two Files SequentiallyThis example demonstrates how to read data from two files one after another using SequenceInputStream. Here, we are assuming that you have two files: testin.txt and testout.txt which have following information: testin.txt: Welcome to Java IO Programming. testout.txt: It is the example of Java SequenceInputStream class. After executing the program, you will get following output: Output: Welcome to Java IO Programming. It is the example of Java SequenceInputStream class. Example 2: Reading from Two Files and Writing into Another FileThis example demonstrates how to read data from two files and write the combined data into another file. Output: Succeess... testout.txt: Example 3: Reading Data from Multiple Files Using EnumerationThis example demonstrates how to read data from more than two files using SequenceInputStream with Enumeration. The a.txt, b.txt, c.txt and d.txt have following information: a.txt: Welcome b.txt: to c.txt: java d.txt: programming Output: Welcometojavaprogramming Next TopicJava ByteArrayOutputStream Class |
We request you to subscribe our newsletter for upcoming updates.