class ClientMain {

    static CompletionStage<Void> saveResponseToFile(WebClient webClient) {
        //We have to create file subscriber first. This subscriber will save the content of the response to the file.
        Path file = Paths.get("test.txt");
        try {
            Files.deleteIfExists(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        FileSubscriber fileSubscriber = FileSubscriber.create(file);

        //Then it is needed obtain unhandled response content and subscribe file subscriber to it.
        System.out.println("Downloading server response to the file: " + file);
        return webClient.get()
                .request()
                .thenApply(WebClientResponse::content)
                .thenCompose(fileSubscriber::subscribeTo)
                .thenAccept(path -> System.out.println("Download complete!"));
    }

    private  ClientMain();

}