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...");
            
        }
    
    
       
    }
  • 相关阅读:
    HDU 1421 DP
    HDU1011 树形DP
    CodeForces 219D 树形DP
    HDU2196 树形DP
    HDU5831
    HDU3177 贪心
    数位DP HDU3652
    数位DP bzoj1026
    数位DP HDU3555
    数位DP HDU2089
  • 原文地址:https://www.cnblogs.com/Donnnnnn/p/7727782.html
Copyright © 2011-2022 走看看