Skip to content

Instantly share code, notes, and snippets.

@atechcrew
Created July 9, 2018 13:40
Show Gist options
  • Save atechcrew/66e2b9ce4ec465f8f68dc9c8d9c24963 to your computer and use it in GitHub Desktop.
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.
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