zoukankan      html  css  js  c++  java
  • 通过java 来实现对多个文件的内容合并到一个文件中

    现在有多个txt文本文件,需要把这么多个文件的内容都放到一个文件中去

    以下是实现代码

    package com.SBgong.test;
    import java.io.*;
    
    public class FileCombine {
        public static  void  main(String[] args) throws IOException {
           //定义输出目录
            String FileOut="E:\Mycode\SBgong\output\1.txt";
            BufferedWriter bw=new BufferedWriter(new FileWriter(FileOut));
    
          //读取目录下的每个文件或者文件夹,并读取文件的内容写到目标文字中去
            File[] list = new File("E:\Mycode\SBgong\input\2012-09-22").listFiles();
            int fileCount = 0;
            int folderConut= 0;
            for(File file : list)
            {
                if(file.isFile())
                {
                    fileCount++;
                    BufferedReader br = new BufferedReader(new FileReader(file));
                    String line;
                    while((line=br.readLine())!=null) {
                        bw.write(line);
                        bw.newLine();
                    }
                    br.close();
                }else {
                    folderConut++;
                }
            }
            bw.close();
            System.out.println("输入目录下文件个数为"+fileCount);
            System.out.println("输入目录下文件夹个数为"+folderConut);
    
        }
    
    }

    运行结果:

     

  • 相关阅读:
    原子核壳模型程序 BigStick 的用法
    c++ 中的下三角阵矩阵元标记
    BCS方程和Bogoliubov变换
    圆膜振动问题
    核结构单体跃迁算符
    python画球谐函数
    gnuplot 绘制球谐函数图
    shell 脚本小知识集锦
    6.12学习总结
    PHP网上商城
  • 原文地址:https://www.cnblogs.com/braveym/p/10810153.html
Copyright © 2011-2022 走看看