Thứ Sáu, 30 tháng 8, 2013

download image from url and save to file java


    public static void downloadImage(String imageUrl, String savePath) throws   MalformedURLException, IOException {
        Connection conn = Jsoup.connect(imageUrl);
        conn = conn.timeout(10000).ignoreContentType(true);
        Connection.Response resultImageResponse = conn.execute();
        FileOutputStream out = (new FileOutputStream(new java.io.File(savePath)));
        out.write(resultImageResponse.bodyAsBytes());          
        out.close();
    }

Không có nhận xét nào:

Đăng nhận xét