FileCopy.java
import java.io.FileReader
import java.io.FileWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
public class FileCopy {
public static void main(String[] args) throws IOException{
FileReader reader = null;
FileWriter writer=null;
try {
reader=new FileReader(args[0]);
writer=new FileWriter(args[1]);
in c;
while (( c=reader.read())!=-1) {
writer.write(c);
}
}
catch (ArrayIndexOutOfBouldsException aex){
System.out.println("Incorrect number of arguments:"+aex.getMessage() )
}
catch(FileNotFoundException fnfex) {
System.out.println("FileNotFoundException Err: " +fnfex.getMessage());
}
catch(IOException ioex) {
System.out.println("IOException Err:" + ioex.getMessage());
}
finally{
if (reader != null){
reader.close();
}
if (writer !=null) {
writer.close();
}
}
}
}
沒有留言:
張貼留言