• 黑马程序员JAVA高级视频_IO输入与输出20天9(切割合并文件)


    package string.test;
    
    import java.io.*;
    import java.util.Vector;
    
    /*
     * 切割文件
     */
    public class SplitFile {
        public static void main(String[] args) throws IOException {
            // splitFile();
            merge();
        }
    
        /*
         * 合并文件
         */
        public static void merge() throws IOException {
            Vector<FileInputStream> fileInputStreams = new Vector<FileInputStream>();
            for (int i = 1; i <= 7; i++) {
                fileInputStreams.add(new FileInputStream("g:\\split" + i + ".rar"));
            }
            SequenceInputStream sis = new SequenceInputStream(fileInputStreams.elements());
            FileOutputStream fos = new FileOutputStream("f:\\alipaydirect.rar");
            byte[] bytes = new byte[1024 * 1024];
            int len = 0;
            while ((len = sis.read(bytes)) != -1) {
                fos.write(bytes, 0, len);
            }
            sis.close();
            fos.close();
    
        }
    
        /*
         * 切割文件
         */
        public static void splitFile() throws IOException {
            FileInputStream fis = new FileInputStream("g:\\alipaydirect.rar");
            FileOutputStream fos = null;
            byte[] bytes = new byte[1024 * 1024];
            int len = 0;
            int count = 1;
            while ((len = fis.read(bytes)) != -1) {
                fos = new FileOutputStream("g:\\split" + count + ".rar");
                count++;
                fos.write(bytes, 0, len);
                fos.flush();
                fos.close();
            }
            fis.close();
        }
    }
  • 相关阅读:
    Docker 国内镜像源
    SeMF安装指南
    CGI environment variables
    OpenResty + ngx_lua_waf使用
    OpenResty源码编译安装
    Ubuntu安装DVWA
    C安全编码实践
    [译]The Complete Application Security Checklist
    HTTP 安全头配置
    AWVS 10.5使用指南
  • 原文地址:https://www.cnblogs.com/guwenren/p/2980980.html
Copyright © 2020-2023  润新知