-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownload.java
More file actions
24 lines (22 loc) · 760 Bytes
/
Copy pathDownload.java
File metadata and controls
24 lines (22 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.io.IOException;
import java.net.*;
public class Download {
public static String download(String sourceUrl){
System.out.println("Downloading : "+ sourceUrl);
try {
URL url = new URI(sourceUrl).toURL();
HttpURLConnection con = (HttpURLConnection)url.openConnection();
int response = con.getResponseCode();
if(response>= 200 && response<300){
return IOUtil.read(con.getInputStream());
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
}