zoukankan      html  css  js  c++  java
  • 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();
    }
    }

  • 相关阅读:
    UART协议
    芯片时钟体系(take example as s3c2440)
    PCIe协议
    I2C协议
    SPI协议
    嵌入式相关术语列表
    TreeView控件数据绑定之:数据库数据递归绑定
    连接SQL Server 数据库的三种方式
    JS小功能之:五角星评论
    MVC学习之开发技巧总结(1)
  • 原文地址:https://www.cnblogs.com/hfew/p/10600638.html
Copyright © 2011-2022 走看看