outstream代码

输出流的用法
www.baidu.com

姓名 年龄 爱好
王二 18
`package com.javastudy.IO;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Copy01 {
public static void main(String[] args) {
FileOutputStream fos = null;
FileInputStream fis = null;
try {
fis = new FileInputStream("D:\IO练习文件夹\aa.txt");
fos = new FileOutputStream("C:\apq.txt"); //C盘存在安全问题,不能被Copy进去

        byte[] bytes = new byte[1024*1024]; //最多可以copy  1M
        int readCount = 0;
        while((readCount = fis.read(bytes))!=-1){
            System.out.println(new String(bytes,0,readCount));
        }

        fos.flush();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }finally {
        if(fis != null){
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if(fos != null){
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

}
`

posted @ 2020-11-09 20:20  啦啦啦。。  阅读(63)  评论(0)    收藏  举报