- import java.io.BufferedOutputStream;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.SequenceInputStream;
- /*
- * 合并流案例1
- * 将两个文件的内容复制到一个文件中
- */
- public class Demo5 {
- public static void main(String[] args) throws IOException {
- SequenceInputStream sis = new SequenceInputStream(new FileInputStream(
- "F:\\path变量备份.txt"), new FileInputStream("F:\\path变量备份.txt"));
- BufferedOutputStream bos = new BufferedOutputStream(
- new FileOutputStream("合并后.txt"));
- byte[] bys = new byte[1024];
- int len = 0;
- while ((len = sis.read(bys)) != -1) {
- bos.write(bys, 0, len);
- }
- sis.close();
- bos.close();
-
- }
- }
复制代码 实现两个文件夹的内容合并后写入到一个文件夹中。
|
|