• day31 用缓冲流复制文件


    package zuoye;

    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.FileWriter;

    public class zuoye {
    public static void main(String[] args) throws Exception{
    fu();
    fu1();
    fu2();
    fu3();
    }
    //字节缓冲流复制文件用非数组
    public static void fu() throws Exception{
    BufferedInputStream a=new BufferedInputStream(new FileInputStream("D:\timg.jpg"));
    BufferedOutputStream b=new BufferedOutputStream(new FileOutputStream("E:\a.jpg"));
    int i=0;
    while((i=a.read())!=-1){
    b.write(i);
    }
    b.close();
    a.close();
    }
    //字节缓冲流复制文件用数组
    public static void fu1() throws Exception{
    BufferedInputStream a=new BufferedInputStream(new FileInputStream("D:\timg.jpg"));
    BufferedOutputStream b= new BufferedOutputStream(new FileOutputStream("E:\a1.jpg"));
    byte[] c=new byte[1024*10];
    int i=0;
    while((i=a.read(c))!=-1){
    b.write(c,0,i);
    }
    b.close();
    a.close();
    }
    //字符缓冲流复制文件用非数组
    public static void fu2() throws Exception{
    BufferedReader a=new BufferedReader(new FileReader("D:\timg.jpg"));
    BufferedWriter b=new BufferedWriter(new FileWriter("E:\a2.jpg"));
    int i=0;
    while((i=a.read())!=-1){
    b.write(i);
    }
    b.close();
    a.close();
    }
    //字符缓冲流复制文件用数组
    public static void fu3() throws Exception{
    BufferedReader a=new BufferedReader(new FileReader("D:\timg.jpg"));
    BufferedWriter b=new BufferedWriter(new FileWriter("E:\a3.jpg"));
    char[] c1=new char[1024*10];
    int i=0;
    while((i=a.read(c1))!=-1){
    b.write(c1,0,i);
    }
    b.close();
    a.close();
    }
    }

  • 相关阅读:
    OSError: cannot open resource(pillow错误处理)
    boost 库中文教程
    博客案例
    requests模块
    浅析Python中的struct模块
    面试基础知识点总结
    ant安装、环境变量配置及验证
    TestNG学习-001-基础理论知识
    selenium 常见面试题以及答案
    HTML5
  • 原文地址:https://www.cnblogs.com/hfew/p/10600638.html
Copyright © 2020-2023  润新知