请问使用SequenceInputStream顺序流类是否可以把2个或者多个InputStream连接起来当做一个流使用呢..如果可以请问如何实现

Nickcour 2003-10-16 05:12:50
请问使用SequenceInputStream顺序流类是否可以把2个或者多个InputStream连接起来当做一个流使用呢..如果可以请问如何实现
...全文
56 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Shrewdcat 2003-11-14
  • 打赏
  • 举报
回复
SequenceInputStream

public SequenceInputStream(InputStream s1,InputStream s2)

Initializes a newly created SequenceInputStream by remembering the two arguments, which will be read in order, first s1 and then s2, to provide the bytes to be read from this SequenceInputStream.

Parameters:
s1 - the first input stream to read.
s2 - the second input stream to read.

例子可以看 sundaylihongbo(星期天) 提供的。
北方的狼 2003-11-14
  • 打赏
  • 举报
回复
当然可以,如下:
public static void main(String[] args)throws IOException{
String file1,file2;
file1 = "test.txt";
file2 = "test1.txt";
SequenceInputStream sis = new SequenceInputStream(
new FileInputStream(file1),new FileInputStream(file2));
BufferedReader br = new BufferedReader(
new InputStreamReader(sis));
String s;
while((s = br.readLine())!=null)
System.out.println(s);
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧