java 填空题目
横线处为填空的地方编制一个程序,将c:\test1.txt、c:\test2.txt两个文件的内容合并到一个c:\testall.txt文件中。importjava.io...
横线处为填空的地方
编制一个程序,将c:\test1.txt、c:\test2.txt两个文件的内容合并到一个c:\testall.txt文件中。
import java.io.*;
public class test4B{
public static void main(String args[]) throws IOException{
File f1 = new File("c:/test1.txt");
File f2 = new File("c:/test2.txt");
File f3 = new File("c:/testall.txt");
FileInputStream fis = new FileInputStream(f1);
____________________________________________________
InputStream sis = new SequenceInputStream(fis, fis1);
InputStreamReader isr = new InputStreamReader(sis);
____________________________________________________
____________________________________________________
int c;
____________________________________________________
osw.write((char)c);
}
System.out.println("ok....");
____________________________________________________
osw.close();
}
} 展开
编制一个程序,将c:\test1.txt、c:\test2.txt两个文件的内容合并到一个c:\testall.txt文件中。
import java.io.*;
public class test4B{
public static void main(String args[]) throws IOException{
File f1 = new File("c:/test1.txt");
File f2 = new File("c:/test2.txt");
File f3 = new File("c:/testall.txt");
FileInputStream fis = new FileInputStream(f1);
____________________________________________________
InputStream sis = new SequenceInputStream(fis, fis1);
InputStreamReader isr = new InputStreamReader(sis);
____________________________________________________
____________________________________________________
int c;
____________________________________________________
osw.write((char)c);
}
System.out.println("ok....");
____________________________________________________
osw.close();
}
} 展开
展开全部
源码奉上,测试可行,望采纳
File f1 = new File("D:/1.txt");
File f2 = new File("D:/2.txt");
File f3 = new File("D:/a.txt");
FileInputStream fis = new FileInputStream(f1);
FileInputStream fis1 = new FileInputStream(f2);
FileOutputStream fos = new FileOutputStream(f3, true);
InputStream sis = new SequenceInputStream(fis, fis1);
InputStreamReader isr = new InputStreamReader(sis);
OutputStreamWriter osw = new OutputStreamWriter(fos);
int c;
while((c=isr.read())!=-1){
osw.write((char)c);
}
System.out.println("ok....");
isr.close();
osw.close();
File f1 = new File("D:/1.txt");
File f2 = new File("D:/2.txt");
File f3 = new File("D:/a.txt");
FileInputStream fis = new FileInputStream(f1);
FileInputStream fis1 = new FileInputStream(f2);
FileOutputStream fos = new FileOutputStream(f3, true);
InputStream sis = new SequenceInputStream(fis, fis1);
InputStreamReader isr = new InputStreamReader(sis);
OutputStreamWriter osw = new OutputStreamWriter(fos);
int c;
while((c=isr.read())!=-1){
osw.write((char)c);
}
System.out.println("ok....");
isr.close();
osw.close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询