I/O-----字节输入流

时间:2024-09-23 21:05:44

package io.day03;

import java.io.FileInputStream;

import java.io.InputStream;

public class day03 {

public static void main(String[] args) throws Exception {

//路径+文件名

InputStream is =new FileInputStream("src/a.txt");

byte[] bs =new byte[10];

//把指定长度的字节放入bs的数组中,并返回读取的实际长度

//  int length =is.read(bs);

//  System.out.println(length);

//  System.out.println(Arrays.toString(bs));

//  for(int b:bs){

//   System.out.println((char)b);

//  }

while(true){

int length =is.read(bs);

for(int i=0;i<length;i++){

System.out.print((char)bs[i]);

}

System.out.println();

if(length<10){

break;

}

}

}

}