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

  • 相关阅读:
    shell命令finger
    join命令
    日志记录
    shell命令xargs
    linux read 简介
    P1601 A+B Problem(高精)
    P2670 [NOIP2015 普及组] 扫雷游戏
    P1042 [NOIP2003 普及组] 乒乓球
    P1328 [NOIP2014 提高组] 生活大爆炸版石头剪刀布
    P5744 【深基7.习9】培训
  • 原文地址:https://www.cnblogs.com/hfew/p/10600638.html
Copyright © 2011-2022 走看看