使用最近稳定的Spring WebFlux(截至撰写时为5.2.4.RELEASE):
final WebClient client = WebClient.create("https://example.com");final Flux<DataBuffer> dataBufferFlux = client.get() .accept(MediaType.TEXT_HTML) .retrieve() .bodyToFlux(DataBuffer.class); // the magic happens herefinal Path path = FileSystems.getDefault().getPath("target/example.html");DataBufferUtils .write(dataBufferFlux, path, CREATE_NEW) .block(); // only block here if the rest of your pre is synchronous对我来说,最不明显的部分是
bodyToFlux(DataBuffer.class),正如有关
Spring文档流的通用部分中当前提到的,在WebClient部分中没有直接引用它。


![Spring WebClient:如何将大byte []流式传输到文件? Spring WebClient:如何将大byte []流式传输到文件?](http://www.mshxw.com/aiimages/31/419770.png)
