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

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();
}
}
}
}

最后

以上就是清脆鸵鸟最近收集整理的关于 将一个文件夹下的多个文件合并到一个文件中的全部内容,更多相关内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部