[size=x-small]public void copyFile(String path1,String path2){
try {
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(path1)));
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(path2)));
byte[] buf = new byte[1024];
int b;
while((b=in.read())!=-1){
out.write(buf,0,b);
}
in.close();
out.close();
System.out.println("文件复制成功");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}[size=x-small][/size][size=small][/size][/size]
while((b=in.read())!=-1){
改成:
while((b=in.read(buf))!=-1){
也可以参考一下下面的文章:
[url]http://blogzhoubo.iteye.com/admin/blogs/805044[/url]
在out.close(); 前写上out.flush()