public class Demo4 {
public static void main(String[] args) {
//创建输入流对象
FileInputStream inputStream=new FileInputStream(new File("a.txt"));
FileInputStream in=new FileInputStream("a.txt");
// read
// read单个字节
//readSinngle(in);
// read字节数组
//创建一个容器杯子
byte[] bytes = new byte[1024];
// readMulti(in , bytes);
// read字节数组 的部分
int readCount =0;
try {
readCount=in.read(bytes,0,bytes.length);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(new String(bytes,0,readCount));
// close
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void readMUlti(FileInputStream in, byte[] bytes) throws IOException{
int readCount =in.read();
System.out.println(readCount);
// 把字节数据转化为字符串利用String的构造方法
String s = new String(bytes , 0 , readCount);
System.out.println(s);
}
private static void readSingle(FileInputStream in) throws IOException{
int readData =in.read();
System.out.println(readData);
int readData2 = in.read();
System.out.println(readData2);
int readData3 = in.read();
System.out.println(readData3);
int readData4 =in.read();
System.out.println(readData4);
}
}