java 字符流

1.FileReader

2.FileWriter

3.复制文件

package com.ligy.studymvc.main3;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.text.SimpleDateFormat;

public class main {
    public static void main(String[] args) throws Exception {
        //复制文件
        System.out.println("程序开始执行:");
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateStr = dateformat.format(System.currentTimeMillis());
        System.out.println(dateStr);
        String f1 = "C:\\Users\\ASUS\\Desktop\\1.txt";
        String f2 = "D:\\1.txt";
        FileWriter fileOutputStream = new FileWriter(f2);
        FileReader fileInputStream = new FileReader(f1);
        char[] bs = new char[1024];
        int len = 0;
        while ((len = fileInputStream.read(bs)) != -1) {
            fileOutputStream.write(bs, 0, len);

            System.out.println(new String(bs));
        }

        fileOutputStream.close();
        fileInputStream.close();
        System.out.println("程序结束执行:");
        String dateStr2 = dateformat.format(System.currentTimeMillis());
        System.out.println(dateStr2);
    }
}

 

posted on 2022-01-03 08:22  biind  阅读(24)  评论(0编辑  收藏  举报