【问题标题】:android-async-http loopj set saving path for downloading fileandroid-async-http loopj 设置下载文件的保存路径
【发布时间】:2013-12-04 11:20:28
【问题描述】:

请告诉我如何设置下载文件的保存路径。

例如:

AsyncHttpClient client = new AsyncHttpClient();
String[] allowedTypes = new String[] { "image/png" };
client.get("http://www.example.com/image.png", new BinaryHttpResponseHandler(allowedTypes) {
    @Override
    public void onSuccess(byte[] imageData) {
        // Successfully got a response
    }

    @Override
    public void onFailure(Throwable e, byte[] imageData) {
        // Response failed :(
    }
 });

【问题讨论】:

  • 非常简短的解释。尽量简述问题
  • 这个是lib loopj的使用问题。特别是如何设置要加载的文件的路径。 Aamirkhan 先生,如果问题不清楚,我很抱歉为什么要加减号

标签: android loopj android-async-http


【解决方案1】:

您需要将此字节数组与 OutputStream 子类一起使用以将字节写入磁盘,

OutputStream f = new FileOutputStream(new File("path"));
f.write(bytes); //your bytes
f.close();

此代码会将文件写入磁盘,以获取路径,将文件保存在变量上并使用 File.getAbsolutePath()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多