不多说,上代码:
//复制文件
public static void CopyFile(String fromfile,String tofile){
try {
FileInputStream fosfrom = new java.io.FileInputStream(fromfile);
FileOutputStream fosto = new FileOutputStream(tofile);
byte bt[] = new byte[1024];
int c;
while ((c = fosfrom.read(bt)) > 0) {
fosto.write(bt, 0, c); //将内容写到新文件当中
}
fosfrom.close();
fosto.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}