public class work3 {
public static void main(String[] args) throws IOException {
getFile();
}
//通過建立緩沖區和循環的方式來讀取
public static void getFile() throws IOException{
//1.找目標文件
File file = new File("C:\\abcd\\12.5.txt");
//2.建立通道
FileInputStream fileInputStream = new FileInputStream(file);
//3.創建緩沖區
byte[] b = new byte[1024];
//4.讀取數據
int count = 0;
while((count = fileInputStream.read(b))!=-1){
System.out.println(new String(b,0,count));
//是說把數組b中的元素付給String,0是指偏移量,從數組第0個開始
}
fileInputStream.close();
}
}
