Created
July 9, 2018 13:40
-
-
Save atechcrew/66e2b9ce4ec465f8f68dc9c8d9c24963 to your computer and use it in GitHub Desktop.
Download Image from web using java. Java code to download image from website.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedInputStream; | |
import java.io.BufferedOutputStream; | |
import java.io.FileOutputStream; | |
import java.io.InputStream; | |
import java.io.OutputStream; | |
import java.net.URL; | |
public class DownloadImage { | |
public static void main(String args[]) { | |
try { | |
URL url = new URL("complete image url"); | |
InputStream readImage = new BufferedInputStream(url.openStream()); | |
OutputStream storeImage = new BufferedOutputStream(new FileOutputStream("image.jpg")); | |
for ( int i; (i = readImage.read()) != -1; ) { | |
storeImage.write(i); | |
} | |
readImage.close(); | |
storeImage.close(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment