我有很多.txt
文件。我想将它们连接起来并生成一个文本文件。
我将如何用Java做到这一点?
file1.txt file2.txt
串联结果成
file3.txt
使得内容的file1.txt
后面file2.txt
。
逐文件读取并将其写入目标文件。类似于以下内容:
OutputStream out = new FileOutputStream(outFile);
byte[] buf = new byte[n];
for (String file : files) {
InputStream in = new FileInputStream(file);
int b = 0;
while ( (b = in.read(buf)) >= 0)
out.write(buf, 0, b);
in.close();
}
out.close();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句