반응형
SequenceInputStream
- 서로 다른 InputStream을 연결해 주는 역할을 함.
- 2개 이상의 InputStream은 배열 형식으로 처리
=================================================================================================
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.SequenceInputStream;
public class SequenceInputTest01 {
public static void main(String[] args) throws Exception{
int bn;
byte[] arr = {'J', 'a', 'v', 'a', '.'};
ByteArrayInputStream bi = new ByteArrayInputStream(arr);
FileInputStream fi = new FileInputStream("C:/Test/sequence.txt");
SequenceInputStream si = new SequenceInputStream(fi, bi);
while( (bn = si.read()) != -1){
System.out.write(bn);
}
System.out.flush();
}
}
=====================================================================================================
import java.io.FileInputStream;
import java.io.SequenceInputStream;
import java.util.Vector;
/**
* 2개 이상의 InputStream은 배열 형식으로 처리
* @author sharkmino
*
*/
public class SequenceInputTest02 {
public static void main(String[] args) throws Exception{
int bn = 0;
FileInputStream fi1 = new FileInputStream("C:/Test/sequence01.txt");
FileInputStream fi2 = new FileInputStream("C:/Test/sequence02.txt");
FileInputStream fi3 = new FileInputStream("C:/Test/sequence03.txt");
Vector v = new Vector();
v.addElement(fi1);
v.addElement(fi2);
v.addElement(fi3);
SequenceInputStream si = new SequenceInputStream(v.elements());
while( (bn = si.read()) != -1){
System.out.write(bn);
}
System.out.flush();
}
}
반응형
'프로그래밍 정리 > 자바' 카테고리의 다른 글
PushbackInputStream (0) | 2013.06.01 |
---|---|
flush() (0) | 2013.06.01 |
BufferedInputStream와 BufferedOutputStream (0) | 2013.06.01 |
DataInputStream과 DataOutputStream (0) | 2013.06.01 |
StreamTokenizer (0) | 2013.06.01 |