假设有一个网站,将一个文件分割为了1000个RAR来下载URL为 http://font.flash8.net/download.aspx?app=font&id=1
到 http://font.flash8.net/download.aspx?app=font&id=1000而这些文件又存放于 http://file5.flash8.net/font/2005/rar/ 目录下我试着写了一个程序一次性将其全部下载下来可是没成功,哪位帮忙看看!谢谢    public void downloadFile() throws IOException
    {
        for( int i = 1;i < 1000; i++ )
        {
            String location = "http://font.flash8.net/download.aspx?app=font&id=";
            String path = "http://file5.flash8.net/font/2005/rar/3291_383_391.rar";
            location = location + String.valueOf(i);
            this.getResourceAsStream( location );
        }    }    public final InputStream getResourceAsStream(String location) throws IOException
    {
        URL url = new URL(location);
        return url.openStream();
    }

解决方案 »

  1.   

    楼主不要用throws IOException,而是用try和catch,看看是否有异常抛出,然后再决定解决方案
      

  2.   

    public void downloadFile_( String strTempDir , String httpUrl)
        {
            try
            {
                URL url = null;            url = new URL( httpUrl );            BufferedInputStream input = new BufferedInputStream(url.openStream());
                BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(strTempDir));            byte[] buf = new byte[1024*1024];            int len = input.read(buf, 0, buf.length);
                while (len != -1)
                {
                    out.write(buf, 0, len);
                    len = input.read(buf, 0, buf.length);
                }            input.close();
                input = null;
                out.close();
                out = null;
            }
            catch(Exception e)
            {
                System.out.println(e);
            }
        }    public void downloadFile() throws IOException
        {
            for( int i = 3290;i < 3292; i++ )
            {
                String strTempDir = "c:\\fonts\\" + String.valueOf(i) + ".rar";            String location = "http://font.flash8.net/download.aspx?app=font&id=";
                location = location + String.valueOf(i);            this.downloadFile_( strTempDir , location );
            }
        }