Java by API/java.io/SequenceInputStream — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 17:43, 31 мая 2010
Содержание
new SequenceInputStream(Enumeration<? extends InputStream> arg0)
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.util.Vector;
public class Main {
public static void main(String[] args) throws IOException {
Vector theStreams = new Vector();
for (int i = 0; i < args.length; i++) {
FileInputStream fin = new FileInputStream(args[i]);
theStreams.addElement(fin);
}
InputStream in = new SequenceInputStream(theStreams.elements());
for (int i = in.read(); i != -1; i = in.read()) {
System.out.write(i);
}
}
}
new SequenceInputStream(InputStream s1, InputStream s2)
import java.io.FileInputStream;
import java.io.IOException;
import java.io.SequenceInputStream;
public class Main {
public static void main(String args[]) throws IOException {
FileInputStream f1 = new FileInputStream("ByteArrayIOApp.java");
FileInputStream f2 = new FileInputStream("FileIOApp.java");
SequenceInputStream inStream = new SequenceInputStream(f1, f2);
boolean eof = false;
int byteCount = 0;
while (!eof) {
int c = inStream.read();
if (c == -1)
eof = true;
else {
System.out.print((char) c);
++byteCount;
}
}
System.out.println(byteCount + " bytes were read");
inStream.close();
f1.close();
f2.close();
}
}
SequenceInputStream: close()
import java.io.FileInputStream;
import java.io.IOException;
import java.io.SequenceInputStream;
public class Main {
public static void main(String args[]) throws IOException {
FileInputStream f1 = new FileInputStream("ByteArrayIOApp.java");
FileInputStream f2 = new FileInputStream("FileIOApp.java");
SequenceInputStream inStream = new SequenceInputStream(f1, f2);
boolean eof = false;
int byteCount = 0;
while (!eof) {
int c = inStream.read();
if (c == -1)
eof = true;
else {
System.out.print((char) c);
++byteCount;
}
}
System.out.println(byteCount + " bytes were read");
inStream.close();
f1.close();
f2.close();
}
}
SequenceInputStream: read()
import java.io.FileInputStream;
import java.io.IOException;
import java.io.SequenceInputStream;
public class Main {
public static void main(String args[]) throws IOException {
FileInputStream f1 = new FileInputStream("ByteArrayIOApp.java");
FileInputStream f2 = new FileInputStream("FileIOApp.java");
SequenceInputStream inStream = new SequenceInputStream(f1, f2);
boolean eof = false;
int byteCount = 0;
while (!eof) {
int c = inStream.read();
if (c == -1)
eof = true;
else {
System.out.print((char) c);
++byteCount;
}
}
System.out.println(byteCount + " bytes were read");
inStream.close();
f1.close();
f2.close();
}
}