哪位GGJJ能帮我实现下面功能:     将一张JPG的图片从一个目录下面复制到另一个目录下?
     
     谢谢各位GGJJ
                       在线等待。

解决方案 »

  1.   

    InputStream input = new BufferedInputStream(new FileInputStream(new File("D:\\pic175.jpg")));
         byte[] buf = new byte[1024*1024];
         int len = 0;     OutputStream output = new BufferedOutputStream(new FileOutputStream(new File("D:\\upload\\pic175.jpg")));
         while((len = input.read(buf)) >0)
          output.write(buf,0,len);
         input.close();
         output.close();我自己搞定了
                   给大家参考了。
      

  2.   

    需要注意一点:先声明InputStream和OutputStream为null,然后在try里面初始化,最后在finally里面close。如下:InputStream in = null;
    OutputStream out = null;try
    {
        in = new BufferedInputStream(new FileInputStream(new File("D:\\pic175.jpg")));
        out = new BufferedOutputStream(new FileOutputStream(new File("D:\\upload\\pic175.jpg")));    ...
    }
    catch (Exception e)
    {
    }
    finally
    {
        if (in != null)
        {
            try
            {
                in.close();
            }
            catch (Exception e)
            {}
        }
        if (out != null)
        {
            try
            {
                out.close();
            }
            catch (Exception e)
            {}
        }
    }