Connect some in Java Txt file [closed]
•
Java
I have some Txt file I want to connect them and generate a text file How will I execute in Java?
file1.txt file2.txt
Connection results
file3.txt
So file1 Txt followed by File2 txt
Solution
Read and write the target file one by one As follows:
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,b);
out.flush();
}
}
out.close();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
