forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
29 lines (20 loc) · 1006 Bytes
/
Main.java
File metadata and controls
29 lines (20 loc) · 1006 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
25
26
27
28
29
package modern.challenge;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Path;
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
System.out.println("Downloading (please wait) ...");
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://central.maven.org/maven2/org/hibernate/hibernate-core/5.4.2.Final/hibernate-core-5.4.2.Final.jar"))
.build();
HttpResponse<Path> response = client.send(
request, HttpResponse.BodyHandlers.ofFile(Path.of("hibernate-core-5.4.2.Final.jar")));
System.out.println("Status code: " + response.statusCode());
System.out.println("\n Body: " + response.body());
}
}