forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileBodyHandler.java
More file actions
27 lines (20 loc) · 790 Bytes
/
FileBodyHandler.java
File metadata and controls
27 lines (20 loc) · 790 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
package com.zetcode;
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.Paths;
public class FileBodyHandler {
public static void main(String[] args) throws IOException, InterruptedException{
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://webcode.me"))
.GET() // GET is default
.build();
var fileName = "src/resources/index.html";
HttpResponse response = client.send(request,
HttpResponse.BodyHandlers.ofFile(Paths.get(fileName)));
System.out.println(response.statusCode());
}
}