zoukankan      html  css  js  c++  java
  • java字节流复制文件

    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    
    import org.junit.Test;
    
    public class JavaIO {
    
        @Test
        public void test() throws Exception{
            //1、输入输出路径
            String inputPath = "C:\Users\zwx474555\Desktop\E04D24C1-BB2F-424A-AD2D-7B770C96F9A1.png";  //图片路径
            String outPath = "F:\123.png";  //复制路径及文件名
            
            //2、输入输出流对象
            FileInputStream fis = new FileInputStream(inputPath);
            FileOutputStream fos = new FileOutputStream(outPath);
            
            //3、声明字节数组,每次按1K读取,按1K输出
            byte[] bytes = new byte[1024];
            
            int temp = 0;
            while((temp = fis.read(bytes)) != -1){
                fos.write(bytes, 0, temp); //一边读取,一边输出
            }
            //4、刷新输出流
            fos.flush();
            
            //5、关闭流
            fis.close();
            fos.close();
            
        }
    }
  • 相关阅读:
    python 数据类型
    python核心语法
    python 基础知识
    format 用法
    有关python 函数参数
    模拟,队列与堆栈
    字符编码
    [LeetCode] Set Matrix Zeroes
    [LeetCode] Rotate Image
    [LeetCode] Unique Paths
  • 原文地址:https://www.cnblogs.com/StanLong/p/6931656.html
Copyright © 2011-2022 走看看