zoukankan      html  css  js  c++  java
  • Java:多个文档合并输出到一个文档

    多个文档合并输出到一个文档

    方法:Java NIO

    package First;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.nio.channels.FileChannel;
    import java.nio.channels.WritableByteChannel;
    
    public class Test {
    
        
        public static void main(String params[]) throws Exception {
            String[] iF = new String[] {"E:/test1.txt", "E:/test2.txt", "E:/test3.txt", "E:/test4.txt" };
            String oF = "E:/out.txt";
            
            FileOutputStream output = new FileOutputStream(new File(oF));
            WritableByteChannel targetChannel = output.getChannel();
            
            for(int i =0; i<iF.length; i++){
                FileInputStream input = new FileInputStream(iF[i]);
                FileChannel inputChannel = input.getChannel();
                
                inputChannel.transferTo(0, inputChannel.size(), targetChannel);
                
                inputChannel.close();
                input.close();
            }
            targetChannel.close();
            output.close();
            System.out.println("All jobs done...");
            
        }
    
    
       
    }
  • 相关阅读:
    Windows环境下OpenLDAP安装配置
    jobcenter在Windows下连携LDAP
    OpenLDAP搭建
    Go 函数 #3
    Go 数组/多维数组/切片/map #2
    Go内置类型/变量/常量 #1
    git常用命令
    makefile基础_1
    kubernete的service
    配置开发环境
  • 原文地址:https://www.cnblogs.com/Donnnnnn/p/7727782.html
Copyright © 2011-2022 走看看