本帖最后由 魏亮 于 2012-10-12 16:42 编辑
- import java.io.*;
- class CopyPic
- {
- public static void main(String[] args)
- {
- FileInputStream fis = null;
- FileOutputStream fos = null;
- try
- {
- fis = new FileInputStream("pic.bmp");
- fos = new FileOutputStream("pic_2.bmp");
-
- <FONT color=yellowgreen> int ch = 0;
- while ((ch=fis.read())!=-1)
- {
- fos.write(ch);
- }
- </FONT> <FONT color=red>//上边的的方法程序停止,光标闪烁,复制的图片文件无法读取,为什么? 我检查了很多遍,实在想不出??
- /*下边的方法可以复制成功
- </FONT> <FONT color=yellowgreen> byte[] buf = new byte[1024];
- int len=0;
- while((len=fis.read(buf))!=-1)
- {
- fos.write(buf,0,len);
- }
- </FONT> <FONT color=red> * /
- </FONT> catch (IOException e)
- {
- System.out.println(e.toString());
- }
- finally
- {
- try
- {
- if(fis!=null)
- fis.close();
- }
- catch (IOException e)
- {
- System.out.println(e.toString());
- }
- try
- {
- if(fos!=null)
- fis.close();
- }
- catch (IOException e)
- {
- System.out.println(e.toString());
- }
- }
- }
-
- }
复制代码 |