黑马程序员技术交流社区

标题: 求解 [打印本页]

作者: 盛亚昆    时间: 2012-3-25 18:00
标题: 求解
import java.io.*;
class  fuZhi
{
        public static void main(String[] args)
        {
                FileOutputStream fos=null;//作用整个类
                FileInputStream fis=null;

                try
                {
                        fos= new FileOutputStream("D:\\1.JPEG");//复制的
                        fis=new FileInputStream("E:\\2.JPEG");//原文件
                       
                        byte[] buf=new byte[1024];
                        int len =0;
                        while ((len=fis.read(buf))!=-1)//读取数组
                        {
                                fos.write(buf,0,len);

                        }
                       
                }
                catch (IOException e)
                {
                        throw new RuntimeException("复制失败");
                }
                finally
                {
                try
                {
                        if (fis!=null)
                            fis.close();
                       
                }
                catch (IOException e)
                {
                        throw new RuntimeException("读取失败");
                }
                try
                {
                        if (fos!=null)
                            fos.close();
                       
                }
                catch (IOException e)
                {
                        throw new RuntimeException("写入关闭失败");
                }
               
               
                }
               
        }
}
求解
Exception in thread "main" java.lang.RuntimeException: 复制失败
        at fuZhi.main(fuzhi.java:34)
作者: 鲍亚坤    时间: 2012-3-25 18:11
  1. fis=new FileInputStream("E:\\2.JPEG");
复制代码
你的E盘有这个图片吗?
如果没有他就会出错

作者: 黄奇耀    时间: 2012-3-25 18:15
我运行过,程序没有问题,有可能是源文件没找到,即2.JPEG图片没有找到。
有一点提醒下:类名第一个字母一般是大写的哦。




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2