参考MSDOS方式下的COPY命令,编写一个应用程序实现文件的复制。使用格式:java Copy 源文件 目标文件,功能是将源文件的内容复制到目标文件
package s3;
import java.io.*;
public class Copy{
public static void main(String args[ ]){
try{ FileReader inOne=new FileReader("a.txt");
BufferedReader inTwo= new BufferedReader(inOne);
FileWriter tofile=new FileWriter("hello.txt");
BufferedWriter out= new BufferedWriter(tofile);
String s=null;
while((s=inTwo.readLine())!=null){
out.write(s);
out.newLine();
}
out.flush();
out.close();
tofile.close();
inOne=new FileReader("hello.txt");
inTwo= new BufferedReader(inOne);
while((s=inTwo.readLine())!=null){
System.out.println(s);
}
inOne.close();
inTwo.close();
}
catch(IOException e){
System.out.println(e.toString());
}
}
}