A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© OnlyStyle 中级黑马   /  2014-11-10 16:34  /  1178 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

private static void copyPic(String resPicPath,String tarPicPath){
                BufferedInputStream is=null;
                BufferedOutputStream os=null;
                byte[] buf=new byte[1024];
                int len=0;
                try {
                        is=new BufferedInputStream(new FileInputStream(resPicPath));
                        os=new BufferedOutputStream(new FileOutputStream(resPicPath));
                        while ((len=is.read(buf))!=-1) {
                                System.out.println("laile");
                                os.write(buf,0,len);
                                os.flush();
                        }
                } catch (FileNotFoundException e) {
                        throw new RuntimeException("文件未找到!") ;
                } catch (IOException e) {
                        e.printStackTrace();
                }
                finally{
                        if (is!=null) {
                                try {
                                        is.close();
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        }
                        if (os!=null) {
                                try {
                                        os.close();
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        }
                }
        }
问下大神,这个程序出错在哪里,每次运行都会将原图片摧毁,还复制不成功。定义在while循环里的打印语句也不运行。。

评分

参与人数 1黑马币 +1 收起 理由
杨佳名 + 1

查看全部评分

3 个回复

倒序浏览
你看看是不是你的路径问题?代码不全,看的不清不楚
回复 使用道具 举报
is=new BufferedInputStream(new FileInputStream(resPicPath));
                        os=new BufferedOutputStream(new FileOutputStream(resPicPath));


这两句图片难道没有后缀名??比如jpg什么的
回复 使用道具 举报
is=new BufferedInputStream(new FileInputStream(resPicPath));
os=new BufferedOutputStream(new FileOutputStream(resPicPath));
这两句里都是resPicPath
还有应该加上必要的路径判存问题
还有注意图片一定要没问题
我改了resPicPath还是不行,搞了好一会
最后发现图片有问题。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马