复制文本的五中方式与复制图片的四种方式

复制文本的五种方式:
1)

public static void main(String[] args) throws IOException{
        FileReader fr=new FileReader("F:\\a.txt");
        FileWriter fw=new FileWriter("D:\\f.txt");
        char[] chs=new char[1024];
        int len=0;
        while((len=fr.read(chs))!=-1){
            fw.write(chs,0,len);
            fw.flush();
        }
        fr.close();
        fw.close();
    }
}

2)

public class CopyFileDemo4 {
    public static void main(String[] args) throws IOException{
        FileReader fr=new FileReader("F:\\a.txt");
        FileWriter fw=new FileWriter("D:\\e.txt");
        int by=0;
        while((by=fr.read())!=-1){
            fw.write(by);
            fw.flush();
        }
        fr.close();
        fw.close();
    }
}

3)

public class CopyFileDemo9 {
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new FileReader("F:\\a.txt"));
        BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\j.txt"));
        int by=0;
        while((by=br.read())!=-1){
            bw.write(by);
            bw.flush();
        }
        br.close();
        bw.close();
    }
}

4)

public class CopyFileDemo10 {
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new FileReader("F:\\a.txt"));
        BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\k.txt"));
        char[] chs=new char[1024];
        int len=0;
        while((len=br.read(chs))!=-1){
            bw.write(chs,0,len);
            bw.flush();
        }
        br.close();
        bw.close();
    }
}

5)

public class CopyFileDemo11 {
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new FileReader("F:\\a.txt"));
        BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\l.txt"));
         String line=null;
         while((line=br.readLine())!=null){
             int len=Integer.parseInt(line); 
             bw.write(line,0,len);
             bw.flush();
         }
        br.close();
        bw.close();
    }
}

复制图片的四种方式:
1)

public class CopyImageDmeo1 {
    public static void  main(String[] args) throws IOException{
        FileInputStream fis = new FileInputStream("F:\\jietu.JPG") ;
        FileOutputStream fos = new FileOutputStream("D:\\study1.JPG") ;
        byte[] bys = new byte[1024] ;
        int len = 0 ;
        while((len=fis.read(bys))!=-1){
            fos.write(bys, 0, len) ;
        }
        fis.close() ;
        fos.close() ;
    }
}

2)

public class CopyImageDmeo2 {
    public static void main(String[] args) throws IOException{
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("F:\\jietu.JPG"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\study2.JPG"));
        byte[] bys=new byte[1024];
        int len=0;
        while((len=bis.read(bys))!=-1){
            bos.write(bys,0,len);
            bos.flush();
        }
        bis.close();
        bos.close();
    }
}

3)

public class CopyImageDmeo3 {
    public static void main(String[] args) throws IOException{
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("F:\\jietu.JPG"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\study3.JPG"));
        int by=0;
        while((by=bis.read())!=-1){
            bos.write(by);
            bos.flush();
        }
        bis.close();
        bos.close();
    }
}

4)

public class CopyImageDmeo4 {
    public static void  main(String[] args) throws IOException{
        FileInputStream fis = new FileInputStream("F:\\jietu.JPG") ;
        FileOutputStream fos = new FileOutputStream("D:\\study4.JPG") ;
        int by=0;
        while((by=fis.read())!=-1){
            fos.write(by);
            fos.flush();
        }
        fis.close();
        fos.close();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值