We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0857058 commit ce02cd3Copy full SHA for ce02cd3
1 file changed
arrays/DownloadImage.java
@@ -0,0 +1,28 @@
1
+package com.zetcode;
2
+
3
+import java.io.FileOutputStream;
4
+import java.io.IOException;
5
+import java.net.URL;
6
7
+public class DownloadImage {
8
9
+ public static void main(String[] args) throws IOException {
10
11
+ var imageUrl = "http://webcode.me/favicon.ico";
12
+ var destinationFile = "favicon.ico";
13
14
+ var url = new URL(imageUrl);
15
16
+ try (var is = url.openStream();
17
+ var fos = new FileOutputStream(destinationFile)) {
18
19
+ byte[] b = new byte[1024];
20
+ int noOfBytes;
21
22
+ while ((noOfBytes = is.read(b)) != -1) {
23
24
+ fos.write(b, 0, noOfBytes);
25
+ }
26
27
28
+}
0 commit comments