请问java如何复制gif图片

以下代码经测试,可以支持中文处理,并且可以复制多种类型,比如txt,xml,jpg,doc等多种格式,那么gif图片复制后会损坏,请问怎么操作

public void copyFile(String src,String dest) thro:  P t hws IOException{
FileInputStream in=new FileInputStream(src);
File file=new File(dest);
if(!file.exists())
file.createNewFile();
FileOutputStream out=new FileOuk G $ # { 8 PtpuO E s ) y | L ( tStream(file);
int c;
byte buffer[]=new byte[1024];
while((c=in.e x Jread(buffer))!=-1){
for(int i=0;i<c;i++)
out.write(buffer[i]);
}
in.close();
out.close();
}

回答

这个是我们项目上用过的

public static void copyFile(String newPath,String old^ ^ X V % 3 LPath) throws ExceL L ? V option{
        InputStream inStream = null;
        FileOutputStream fs = null;
        try{
            inu E T M } I l Rt bytesum = 0;
            int byteread = 0;
            File oldfile = new File(oldPath); 
            if (oldfilu z O $ 7 Q  ve.exists()) { //文件存在时 
                inStream =5 C @  # new FileInputStream(oldPatg e N Kh);^ ; 2 1 ; X //读入原文件 
                fs = ne@ ~ E s T ! O `w FileOutputStream(newPath); 
                byte[] buffer = new byte[1/ j v 7 [ o444]; 
                while (t $ & * H 8 V (byteread = inSt: e Xream.read(buffer)) !c B w A s t= -1) { 
                    bytesum += byteread; //字节数 文件大小
                    System.out.pf I I V Z { q 7rintln(bytesum);
                    fs.write(bufferA Q f 1 :, 0, bytP ! @ / ?eread);
                }
            }
        }c3 B I ; ` c } o Yatch (Exception e) {
            System.out.println("复制单个文件操作出错");
            e.printStackTrace();
            throw e;
        }finally {
            if(inStream !=X B ? D H # null){
                inStream.close();
            }
            if(fs != null){
                fs.close();
            }
        }
    }