- 没有实现程序的健壮性只是实现了一个基础功能
- 没有处理错误的方法
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class Test {
public static void main(String[] args){
copyFile("E:/1234.txt","E:/12345.txt");
}
public static void copyFile(String oldFile,String newFile) {
InputStream is=null;
OutputStream os=null;
try {
is=new FileInputStream(new File(oldFile));
os=new FileOutputStream(new File(newFile));
int len;
byte[] by=new byte[1024];
while ((len=is.read(by))!=0) {
os.write(by, 0, len);
break;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}finally {
try {
if (is!=null||os!=null) {
os.flush();
os.close();
is.close();
}
} catch (Exception e2) {
}
}
}
}