原图片路径:srcpic
目的图片路径:despic
1 public static void copyPic(String srcpic, String despic){ 2 File file1=new File(srcpic); 3 File file2=new File(despic); 4 byte[] b=new byte[(int)file1.length()]; 5 FileInputStream in=null; 6 FileOutputStream out=null; 7 try { 8 in=new FileInputStream(file1); 9 //没有指定文件则会创建 10 out=new FileOutputStream(file2); 11 //read()--int,-1表示读取完毕 12 while(in.read(b)!=-1){ 13 out.write(b); 14 } 15 out.flush(); 16 in.close(); 17 out.close(); 18 } catch (Exception e) { 19 e.printStackTrace(); 20 } 21 }
亲测好使。