I am trying firstly to download the file and its content from Dropbox in Android app using Dropbox Core API but when i execute the following code the app crushes.
EDIT: I have used two functions downloadDropboxFile and copy functions. The problem is that i am getting blank data when i read the local file which is supposed to contain the dropbox file data.
Here is the code where i call the function
 downloadDropboxFile("/userandpass.txt");
     if (mDBApi.getSession().isLinked())
     {
         InputStream instream = new FileInputStream(String.valueOf(getExternalCacheDir()) + "/userandpass.txt");
         InputStreamReader inputreader = new InputStreamReader(instream);
         BufferedReader buffreader = new BufferedReader(inputreader);
         mTestOutput.setText(buffreader.readLine());
     }
Here is the functions
 private boolean downloadDropboxFile(String fileSelected) {
        File dir = new File(String.valueOf(getExternalCacheDir()));
        if (!dir.exists())
            dir.mkdirs();
        try {
            File localFile = new File(dir + fileSelected);
            if (!localFile.exists()) {
                localFile.createNewFile();
                copy(fileSelected, localFile);
            } else {
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return true;
    }
    private void copy(final String dbPath, final File localFile) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                BufferedInputStream br = null;
                BufferedOutputStream bw = null;
                try {
                    DropboxAPI.DropboxInputStream fd = mDBApi.getFileStream(dbPath,null);
                    br = new BufferedInputStream(fd);
                    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) {
                    e.printStackTrace();
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    if (bw != null) {
                        try {
                            bw.close();
                            if (br != null) {
                                br.close();
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }). start();
    }
Dropbox Core API Implementation on Android Studio:
On app/libs i have the:
dropbox-android-sdk-1.6.3.jar httpmime--4.0.3.jar json_simple-1.1.jar
 
     
    