java如何合并在指定目录下的两个文件,放在一个新的文件中。用I/O流做。
------解决方案--------------------------------------------------------
For Example:
- Java code
import java.io.*;public class Api { public static void main(String[] args) throws Exception { File f = new File("D:\\test");// 目录 FileReader fr = null; BufferedReader br = null; File fwrite = new File("D:\\ALLCDR.TXT");// 文件 FileWriter fw = new FileWriter(fwrite);// 写文件流 File[] fall = f.listFiles(); for (int count = 0; count < fall.length; count++) { fr = new FileReader(fall[count]); br = new BufferedReader(fr); String str = br.readLine(); while (str != null) { System.out.println(str); fw.write(str + "\n"); fw.flush(); str = br.readLine(); } br.close(); fr.close(); } fw.close(); }}