Java - URL 이미지 파일로 저장하기


String imgUrl = "http://www.a.com/test_image.jpg";  // 이미지 URL
String imgFilePath = "test_image.jpg";              // 저장할 파일명 (경로 포함)
String imgFormat = "jpg";                         // 저장할 이미지 포맷. jpg, gif 등

getImageFromUrl(imgUrl, imgFilePath, imgFormat);






/**
 * Image URL to File
 */
public void getImageFromUrl(String imgUrl, String imgFilePath, String imgFormat)
{
        try
        {
            // Image 가져오기
            BufferedImage image = ImageIO.read(new URL(imgUrl));
                       
            // Image 저장할 파일
            File imgFile = new File(imgFilePath);
           
            // Image 저장
            ImageIO.write(image, imgFormat, imgFile);
        }
        catch (Exception e)
        {
        }
}