Demo.java:
package cn.xxx.demo;
import java.io.FileInputStream;
import java.io.IOException;
public class Demo {
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream("c:\\a.txt"); // 创建读取流对象。
byte[] b = new byte[1024]; //创建字节数组 (缓存数组)
int len = 0 ;
while( (len = fis.read(b)) !=-1){ // 读取多个字节到缓存数组b中,返回读取长度。 -1表示读到结尾。
System.out.print(new String(b,0,len)); // 将读取到的字节数组转成String。
}
fis.close(); // 关闭资源。
}
}