public static void main(String[] args) {//聲明兩個文件讀入流FileInputStream in1 = null,in2 = null;//聲明一個序列流SequenceInputStream s = null;//聲明一個輸出流FileOutputStream out = null;try {//構(gòu)造兩個被讀入的文件File inputFile1 = new File("d:\\1.txt");File inputFile2 = new File("d:\\2.txt");//構(gòu)造一個輸出文件File outputFile = new File("d:\\1and2.txt");in1 = new FileInputStream(inputFile1);in2 = new FileInputStream(inputFile2);//將兩個輸入流合為一個輸入流s = new SequenceInputStream(in1,in2);out = new FileOutputStream(outputFile);int c;while((c = s.read())!=-1) {out.write(c);}in1.close();in2.close();s.close();System.out.println("ok....");}catch(IOException e) {e.printStackTrace();}}
添加回答
舉報
0/150
提交
取消