各位坛友,我下面这个代码写的有问题吗?为什么复制图片的时候,生成的图片大小不对,但是复制文件的时候,没有问题呢?- import java.io.*;
 
  
- class CopyTest 
 
 - {
 
 -         public static void main(String[] args) 
 
 -         {
 
 -                 File file = new File("e:\\1.jpg");
 
 -                 File copy_file = new File("e:\\copy.jpg");
 
  
-                 copyFile(file,copy_file);
 
 -                 
 
 -         }
 
  
-         public static void copyFile(File file,File copy_file)
 
 -         {
 
 -                 
 
 -                 if(!file.exists())
 
 -                 {
 
 -                         System.out.println("文件不存在,请选择正确的文件!");
 
 -                         return;
 
 -                 }
 
 -                 
 
 -                 BufferedReader bufr = null;
 
 -                 BufferedWriter bufw = null;
 
  
-                 try
 
 -                 {
 
 -                         bufr = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
 
  
-                         bufw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(copy_file)));
 
 -                         
 
 -                         char[] buf = new char[1024];
 
 -                         //String line = null;
 
 -                         int len = 0;
 
 -                         while((len = bufr.read(buf))!= -1)
 
 -                         {
 
 -                                 bufw.write(buf,0,len);
 
 -                                 bufw.flush();
 
 -                         }
 
 -                         
 
 -                 }
 
 -                 catch (IOException e)
 
 -                 {
 
 -                         throw new RuntimeException("复制文件失败");
 
 -                 }
 
 -                 finally
 
 -                 {
 
 -                         try
 
 -                         {
 
 -                                 if(bufr!=null)
 
 -                                         bufr.close();
 
 -                         }
 
 -                         catch (IOException e)
 
 -                         {
 
 -                                 throw new RuntimeException("关闭读取流失败");
 
 -                         }
 
 -                         try
 
 -                         {
 
 -                                 if(bufw!=null)
 
 -                                         bufw.close();
 
 -                         }
 
 -                         catch (IOException ex)
 
 -                         {
 
 -                                 throw new RuntimeException("关闭输出流失败");
 
 -                         }
 
 -                 }
 
 -         }
 
 - }
 
  复制代码 |