我正在尝试使用改进2来下载/上传文件,但找不到任何有关如何操作的教程示例.我的下载代码是:
@GET("documents/checkout")
public Call<File> checkout(@Query(value = "documentUrl") String documentUrl, @Query(value = "accessToken") String accessToken, @Query(value = "readOnly") boolean readOnly);
Run Code Online (Sandbox Code Playgroud)
和
Call<File> call = RetrofitSingleton.getInstance(serverAddress)
.checkout(document.getContentUrl(), apiToken, readOnly[i]);
call.enqueue(new Callback<File>() {
@Override
public void onResponse(Response<File> response,
Retrofit retrofit) {
String fileName = document.getFileName();
try {
System.out.println(response.body());
long fileLength = response.body().length();
InputStream input = new FileInputStream(response.body());
File path = Environment.getExternalStorageDirectory();
File file = new File(path, fileName);
BufferedOutputStream output = new BufferedOutputStream(
new FileOutputStream(file));
byte data[] = new byte[1024];
long total = 0; …Run Code Online (Sandbox Code Playgroud) 我的Android应用程序使用API发送多部分HTTP请求.我成功地得到了这样的响应:
post.setEntity(multipartEntity.build());
HttpResponse response = client.execute(post);
Run Code Online (Sandbox Code Playgroud)
响应是电子书文件(通常是epub或mobi)的内容.我想将其写入具有指定路径的文件,让我们说"/sdcard/test.epub".
文件可能高达20MB,所以它需要使用某种流,但我可以无法绕过它.谢谢!