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);
}
}
}
上面是字節(jié)輸入流的兩個(gè)模版,methord方法是以字節(jié)為單位進(jìn)行輸入,methord1方法是以數(shù)組為單位進(jìn)行輸入。methord1方法最后將數(shù)組轉(zhuǎn)換成字符串類型的時(shí)候要規(guī)定長度以免空間的浪費(fèi)。