java复习

2020-07-03字节缓冲流

2020-07-03  本文已影响0人  智障猿

字节缓冲流

BufferedInputStream bis = new BufferedInputStream(new FileInputStream("fileTest\\fos.txt"));
//一次读一字节
int by;
while ((by = bis.read()) != -1) {
      System.out.println((char)by);
}
 //一次对一字节数组
byte[] bytes = new byte[1024];
int len;//实际读取的长度
while ((len=bis.read(bytes))!=-1){
      System.out.println(new String(bytes,0,len));
}
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("fileTest\\hello.txt"));
bos.write("xiaohonghua".getBytes());
bos.close();
上一篇下一篇

猜你喜欢

热点阅读