import java.io.*;public class FirstInputStream {
/** Creates a new instance of FirstInputStream */
public FirstInputStream() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Syntax - FileInputStream file.");
return;
}
try {
InputStream fileInput = new FileInputStream(args[0]);
int data = fileInput.read();
while (data != -1) {
System.out.write(data);
data = fileInput.read();
}
fileInput.close();
}
catch (IOException e) {
System.out.println("I/O error - " + e);
}
}
}
/** Creates a new instance of FirstInputStream */
public FirstInputStream() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Syntax - FileInputStream file.");
return;
}
try {
InputStream fileInput = new FileInputStream(args[0]);
int data = fileInput.read();
while (data != -1) {
System.out.write(data);
data = fileInput.read();
}
fileInput.close();
}
catch (IOException e) {
System.out.println("I/O error - " + e);
}
}
}
用readLine()方法