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();

}

相关文章:

  • 2022-12-23
  • 2021-06-10
  • 2021-12-03
  • 2021-08-28
  • 2022-12-23
  • 2021-07-27
  • 2022-12-23
  • 2022-02-15
猜你喜欢
  • 2022-12-23
  • 2021-09-28
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2022-12-23
相关资源
相似解决方案