-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageFromLocal.java
More file actions
42 lines (33 loc) · 1.28 KB
/
ImageFromLocal.java
File metadata and controls
42 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package imagePkg;
import java.io.*;
import java.net.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
public class ImageDownloader {
public static void main(String[] args) {
String folderPath = "C:\\Users\\bunty\\Pictures\\Camera Roll";
downloadImage("file:///C:/Users/bunty/Pictures/WhatsApp%20Image%202023-08-20%20at%2021.33.24.jpeg", folderPath);
}
public static void downloadImage(String imageUrl, String folderPath) {
try {
int i=1;
URL url = new URL(imageUrl);
System.out.println("run 1");
try (InputStream in = url.openStream();
OutputStream out = new FileOutputStream(folderPath + File.separator + "image"+(i++)+" "+".jpg")) {
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
System.out.println("run 2");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}