字符缓冲流

 1 public static void main(String[] args) {
 2         try(
 3                 //  此位置只能放资源对象,用完自动关闭资源。
 4                 //  源文件
 5                 InputStream is = new FileInputStream("F:\\Pictures\\夏豆4k+2k+mp4\\夏豆被画脸2 4k.jpg");
 6                 //  包装成高级缓冲字符流输入流
 7                 InputStream bis = new BufferedInputStream(is);
 8                 //  目标地址
 9                 OutputStream os = new FileOutputStream("D:\\WorkSpace\\code\\basic-app\\src\\xd1.jpg");
10                 //  包装成高级缓冲字符流输出流
11                 OutputStream bos= new BufferedOutputStream(os);
12 
13         ) {
14             //  定义一个数组转移数据
15             byte[] bytes = new byte[1024];
16             //  记录每次的字节数
17             int len;
18             while ((len = bis.read(bytes)) != -1){
19                 bos.write(bytes, 0,len);
20             }
21             System.out.println("复制完成~~~");
22 
23         } catch (Exception e) {
24             e.printStackTrace();
25         }
26     }

 

posted @ 2024-01-28 20:39  小※兽  阅读(1)  评论(0编辑  收藏  举报