本帖最后由 aotian16 于 2011-07-28 12:41:22 编辑

解决方案 »

  1.   

    findbug没用过。  你运行一下嘛不测试怎么知道是什么问题列。肉眼谁看的出来
      

  2.   

    findbugs插件找的是静态的可能出现bug的代码啊,
    运行也看不出来问题
      

  3.   

    要说问题,可能也就是  inStream.close(); 如果异常,fs没关掉。你把inStream.close(); 的 throw e1 删掉就得了,关闭失败就失败呗。
      

  4.   

    我也用findBugs试了下。。跑了一下代码,发现没有问题。
    就是提示了一下注释,以及 byte[] buffer = new byte[1444];
      

  5.   

    你这么一说我还真有点眉目了
    前面inStream关闭失败的话, throw出去
    后面就执行不了了, 所以有close的问题
      

  6.   

    这样就OK了
    /**
     * 
     * 
     * @param oldPath
     *            
     * @param newPath
     *            
     * @throws IOException
     */
    private static void copyFile(String oldPath, String newPath)
    throws IOException { int bytesum = 0;
    int byteread = 0;
    File oldfile = new File(oldPath);
    InputStream inStream = null;
    FileOutputStream fs = null;
    try {
    if (oldfile.exists()) {
    inStream = new FileInputStream(oldPath);
    try {
    fs = new FileOutputStream(newPath);
    byte[] buffer = new byte[1444];
    while ((byteread = inStream.read(buffer)) != -1) {
    bytesum += byteread;
    fs.write(buffer, 0, byteread);
    }
    } catch (IOException e) {
    throw e;
    } finally {
    if (fs != null) {
    try {
    fs.close();
    } catch (IOException e1) {
    throw e1;
    }
    }
    }
    }
    } catch (IOException e) {
    throw e;
    } finally {
    if (inStream != null) {
    try {
    inStream.close();
    } catch (IOException e1) {
    throw e1;
    }
    }
    }
    }参考了这个帖子, 一篇好文,写得比较幽默,看者有分!
    很久以前看到过, 
    现在回想起来, 确实有用
      

  7.   

    4楼说的有道理,不过我也findBugs了一下,结果没有发现问题。是我版本太老了吗?
      

  8.   

    可能不是的,
    因为我用的findbugs我们公司改造过的
    里面就有针对这个close问题的项