Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从Dropbox下载所有类型的文件_Android_Download_Dropbox - Fatal编程技术网

Android 从Dropbox下载所有类型的文件

Android 从Dropbox下载所有类型的文件,android,download,dropbox,Android,Download,Dropbox,我正在做Dropbox。我看到文件了。这是我要显示列表的代码: Entry entryCheck = mApi.metadata("/", 100, null, true, null); Log.i("Item Name", entryCheck.fileName()); Log.i("Is Folder", String.valueOf(entryCheck.isDir)); 我从dropbox得到了所有列表,但我的问题是 这里entryCheck.isDir总是给我真实值,如果它是文件或目

我正在做Dropbox。我看到文件了。这是我要显示列表的代码:

Entry entryCheck = mApi.metadata("/", 100, null, true, null);
Log.i("Item Name", entryCheck.fileName());
Log.i("Is Folder", String.valueOf(entryCheck.isDir));
我从dropbox得到了所有列表,但我的问题是

  • 这里entryCheck.isDir总是给我真实值,如果它是文件或目录,那么我如何知道哪个是文件或哪个是目录
  • 我是如何下载这些文件的
  • 我尝试过这个,但不起作用:

    private boolean downloadDropboxFile(String dbPath, File localFile,
            DropboxAPI<?> api) throws IOException {
        BufferedInputStream br = null;
        BufferedOutputStream bw = null;
        try {
            if (!localFile.exists()) {
                localFile.createNewFile(); // otherwise dropbox client will fail
                // silently
            }                   
    
            DropboxInputStream fin = mApi.getFileStream("dropbox", dbPath);
            br = new BufferedInputStream(fin);
            bw = new BufferedOutputStream(new FileOutputStream(localFile));
    
            byte[] buffer = new byte[4096];
            int read;
            while (true) {
                read = br.read(buffer);
                if (read <= 0) {
                    break;
                }
                bw.write(buffer, 0, read);
            }
        } catch (DropboxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            // in finally block:
            if (bw != null) {
                bw.close();
            }
            if (br != null) {
                br.close();
            }
        }
    
        return true;
    }
    
    private boolean downloadDropboxFile(字符串dbPath,文件localFile,
    DropboxAPI)引发IOException{
    BufferedInputStream br=null;
    BufferedOutputStream bw=null;
    试一试{
    如果(!localFile.exists()){
    localFile.createNewFile();//否则dropbox客户端将失败
    //默默地
    }                   
    DropboxInputStream fin=mApi.getFileStream(“dropbox”,dbPath);
    br=新的BufferedInputStream(fin);
    bw=新的BufferedOutputStream(新的FileOutputStream(localFile));
    字节[]缓冲区=新字节[4096];
    int-read;
    while(true){
    read=br.read(缓冲区);
    如果(读取这将起作用

    String inPath ="mnt/sdcard/"+filename;
    File file=new File(inPath);           
    try {
    
        mFos = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        mErrorMsg = "Couldn't create a local file to store the image";
        return false;
    }
    
    mApi.getFile("/"+filename, null, mFos, null);
    
    这将下载文件并将其存储在SD卡位置
    inPath
    。 您必须在新线程中执行此操作,而不是在主线程中。请使用AsyncTask。 这个链接解释了原因