Handling a body response as a file can be accomplished using BodyHandlers.ofFile(), as shown in the following snippet of code:
HttpResponse<Path> responseOfFile = client.send(
request, HttpResponse.BodyHandlers.ofFile(
Path.of("response.json")));
System.out.println("Status code: " + responseOfFile.statusCode());
System.out.println("Body: " + responseOfFile.body());
For specifying the open options, call ofFile(Path file, OpenOption... openOptions).