import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FilterInputStream;
import java.io.IOException;
public class FileInputStreamDemo {
public static void main(String[] args) throws IOException {
methord();
methord1();
}
private static void methord1() throws IOException {
// TODO Auto-generated method stub
FileInputStream fi = new FileInputStream("E:/lishuai.java");
byte[] b = new byte[2014];
int len;
while ((len = fi.read(b)) != -1) {
String s = new String(b, 0, len);
System.out.println(s);
}
}
private static void methord() throws IOException {
// TODO Auto-generated method stub
FileInputStream fi = new FileInputStream("E:/lishuai.java");
int a;
while ((a = fi.read()) != -1) {
System.out.print((char) a);
}
}
}
上面是字节输入流的两个模版,methord方法是以字节为单位进行输入,methord1方法是以数组为单位进行输入。methord1方法最后将数组转换成字符串类型的时候要规定长度以免空间的浪费。