java 字节流

1. FileOutputStream

2. FileInputStream

3. 复制文件

 

package com.ligy.studymvc.main2;

import java.io.FileInputStream;
import java.io.FileOutputStream;
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\\app前端页面\\钉钉密码登录.jpg";
        String f2 = "D:\\钉钉密码登录.jpg";
        FileOutputStream fileOutputStream = new FileOutputStream(f2);
        FileInputStream fileInputStream = new FileInputStream(f1);
        byte[] bs = new byte[100];
        int len = 0;
        while ((len = fileInputStream.read(bs)) != -1) {
            fileOutputStream.write(bs, 0, len);
        }

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

 

上一篇:java-IO流---字节流


下一篇:P592 FileInputStream和FileOutputStream读写非文本文件