2013年10月25日 星期五

java-file-copy fileinputstream

FileCopy.java

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileCopy {
public static void main(String[] args) throws IOException{
FileInputStream in = null; 
FileOutStream out=null;

try {
in=new FileInputStream(args[0]);
out=new FileOutputStream(args[1]);
in c;
while (( c=in.read())!=-1) {
out.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 (in != null){
in.close();
}
if (out i=null) {
out.close();
}
}
}
}

沒有留言:

張貼留言