public void download_images(String download_path,String img_url) throws Exception
    {
        img_url =URIUtil.encodeQuery(img_url);
        URL url = new URL(img_url);
        InputStream in = new BufferedInputStream(url.openStream());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        int n = 0;
        while (-1!=(n=in.read(buf)))
        {
           out.write(buf, 0, n);
        }
        out.close();
        in.close();
        byte[] response = out.toByteArray();

        FileOutputStream fos = new FileOutputStream(download_path);
        fos.write(response);
        fos.close();
    }

arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()