A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 优质码农 中级黑马   /  2015-4-23 00:31  /  534 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

package homework;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/*8、编写程序,采用多种方式,把d:\\video01.avi的内容复制到d:\\video02.avi中
方式1:基本字节流一次读写一个字节
方式2:基本字节流一次读写一个字节数组
方式3:高效字节流一次读写一个字节
方式4:高效字节流一次读写一个字节数组
C:\Users\wkk\Desktop\Java\作业题\day17.doc
*/

public class HomeWork8 {
        public static void main(String[] args) throws IOException {
                File file = new File("C:\\Users\\wkk\\Desktop\\Java\\作业题\\day17.doc");
                File file2=new File("123.doc");
                //methord1(file,file2);
                //methord(file,file2);
                //methord2(file,file2);
                methord3(file,file2);
        }
       
        private static void methord3(File file, File file2) throws IOException {
                BufferedInputStream bis= new BufferedInputStream(new FileInputStream(file));
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file2));
                byte[] buffer = new byte[100];
                int len=-1;
                while((len=bis.read(buffer))!=-1){
                        bos.write(buffer, 0, len);
                }
        }

        private static void methord2(File file, File file2) throws IOException {
                BufferedInputStream bis= new BufferedInputStream(new FileInputStream(file));
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file2));
                int ch = -1;
                while((ch=bis.read())!=-1){
                        bos.write(ch);
                }
                bos.close();
                bis.close();
        }

        private static void methord(File file, File file2) throws IOException {
                FileInputStream fis =new FileInputStream(file);
                FileOutputStream fos = new FileOutputStream(file2);
                byte[] b =  new byte[100];
                int len=-1;
                while((len=fis.read(b))!=-1){
                        fos.write(b, 0, len);
                }
                fis.close();
                fos.close();
        }

        private static void methord1(File file, File file2) throws IOException {
                FileOutputStream fos=new FileOutputStream(file2);
                FileInputStream fis = new FileInputStream(file);
                int ch = -1;
                while ((ch=fis.read())!=-1) {
                        fos.write(ch);
                       
                }
                fis.close();
                fos.close();
        }

       
}


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马