有两个错误,看下面代码。
- import java.io.*;
- class Demo
- {
- public static void main(String[] args)
- {
- FileInputStream fi= null;
- FileOutputStream fo= null;
- try
- {
- fi= new FileInputStream("f:\\1.jpg");
- fo = new FileOutputStream("f:\\2.jpg");
- //1.这里的char改成byte.
- byte[] arr = new byte[1024];
- int len = 0;
- while((len= fi.read(arr))!=-1)
- {
- fo.write(arr,0,len);
- }
- }
- catch (Exception e)
- {
- throw new RuntimeException("shujuyichang");
- }
- finally
- {
- try
- {
- //2."=="改成"!=",下面fo==null也是改成fo!=null
- if(fi!= null)
- fi.close();
- }
- catch (Exception e)
- {
- throw new RuntimeException("shuchu shibai");
- }
- try
- {
- if(fo !=null)
- fo.close();
- }
- catch (Exception e)
- {
- throw new RuntimeException("xieru shibai");
- }
- }
- }
- }
复制代码 |