我是靠谱客的博主 清脆鸵鸟,最近开发中收集的这篇文章主要介绍 将一个文件夹下的多个文件合并到一个文件中,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

public class CombinationToOneFile {

public static void main(String[] args) throws IOException, ParseException {

//将所有文件合并到target.csv中

FileOutputStream afterFos = new FileOutputStream("d:/combination/before12/"
+ "target.csv");
OutputStreamWriter osw = new OutputStreamWriter(afterFos, "utf8");
BufferedWriter out= new BufferedWriter(osw);

//读取要合并的文件所在的文件夹

File file = new File("D:\before12");
String test[];

//读取该文件夹下面所有要合并的文件
test = file.list();
for (int i = 0; i < test.length; i++) {

BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(
"d:/before12/" + test[i]), "utf8"));
String r = br.readLine();
while (r != null) {
out.write(r);
out.newLine();
out.flush();
r = br.readLine();
}
}
}
}

最后

以上就是清脆鸵鸟为你收集整理的 将一个文件夹下的多个文件合并到一个文件中的全部内容,希望文章能够帮你解决 将一个文件夹下的多个文件合并到一个文件中所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部