流
package com.cy.se.io;
import java.io.FileInputStream;
public class FileInputStreamTest01 {
public static void main(String[] args) {
FileInputStream fileInputStream = null;
try {
//准备文件
String file = "D:\JavaHome\ProjectCode\StudyCode\01-spring-se\test.txt";
//创建文件字节输入流
fileInputStream = new FileInputStream(file);
//每次读4个
byte[] b = new byte[4];
//开始读取硬盘文件
int read = fileInputStream.read(b);//4
System.out.println(read);//返回的int 表示读取的字节数.
//把读取的数组转换成字符串
System.out.println(new String(b));//abcd
//在读取数组
fileInputStream.read(b);
//数组转换成字符串,读取范围是0,到最后.
System.out.println(new String(b,0,b.length-1));//efg
}catch (Exception e){
//打印异常信息
e.printStackTrace();
}
//关流
try {
fileInputStream.close();
}catch (Exception e){
e.printStackTrace();
}
}
}