相关疑难解决方法(0)

改造2档文件下载/上传

我正在尝试使用改进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)

upload android download retrofit

28
推荐指数
2
解决办法
3万
查看次数

如何将HttpResponse下载到文件中?

我的Android应用程序使用API​​发送多部分HTTP请求.我成功地得到了这样的响应:

post.setEntity(multipartEntity.build());
HttpResponse response = client.execute(post);
Run Code Online (Sandbox Code Playgroud)

响应是电子书文件(通常是epub或mobi)的内容.我想将其写入具有指定路径的文件,让我们说"/sdcard/test.epub".

文件可能高达20MB,所以它需要使用某种流,但我可以无法绕过它.谢谢!

java apache android

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×2

apache ×1

download ×1

java ×1

retrofit ×1

upload ×1