Download a File with OkHttp
阿新 • • 發佈:2018-12-27
OkHttp 用起來真的很方便。
Download a file with OkHttp synchronously
Here is the sample source code to download a file synchronously then write the file temporarily to disk.
public void downloadFileSync(String downloadUrl) throws Exception { OkHttpClient client = new OkHttpClient(); Request request = new RequestDownload a file with OkHttp asynchronously
Here is the sample code to download a file asynchronously then write it to disk.
public void downloadFileAsync(final String downloadUrl) throws Exception { OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().url(downloadUrl).build(); client.newCall(request).enqueue(new