本帖最后由 刘茂林 于 2013-5-19 14:54 编辑
- import java.io.*;
- import java.lang.*;
- public class Copypic
- {
- public static void main(String[] args)
- {
- FileInputStream fis = null;
- FileOutputStream fos = null;
- try
- {
- fis = new FileInputStream("test.jpg");
- fos = new FileOutputStream("copy.jpg");
- byte[] buf = new byte[1024 * 5];
- int len = 0;
- while ((len = fis.read(buf)) != 0)
- {
- fos.write(buf, 0, len);
- }
- } catch (IOException e)
- {
- System.out.print("复制文件失败" + e.toString());
- }
- finally
- {
- if (fis != null)
- {
- try
- {
- fis.close();
- } catch (IOException e)
- {
- System.out.println("读取关闭失败"+e.toString());
- }
- }
- if (fos != null)
- {
- try
- {
- fos.close();
- } catch (IOException e)
- {
- System.out.println("读取关闭失败"+e.toString());
- }
- }
- }
-
- }
复制代码 不知道怎么回事,运行的时候出现数组越界,但实际上复制成功了 求解答?? |
|