Download a file from a Dropbox Folder Save Into SDcard using Async task in Android Not Working -


1.i want download specific file dropbox folder in android, save local sdcard.

2.i referred dbroulette example downloading random pictures dropbox.

also, tried below code, not getting solution download file.

please me.

link referred- code download images randomly.

private boolean downloaddropboxfile(string dbpath, file localfile) throws ioexception{      bufferedinputstream br = null;     bufferedoutputstream bw = null;      try {         if (!localfile.exists()) {             localfile.createnewfile(); //otherwise dropbox client fail silently         }          filedownload fd = api.getfilestream("dropbox", dbpath, null);         br = new bufferedinputstream(fd.is);         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);         }     } {         //in block:         if (bw != null) {             bw.close();         }         if (br != null) {             br.close();         }     }      return true; } 

you can use following 2 methods copy files under dropbox directory new one.

public static final void copydirectory(file dropboxfile, file newfile) throws ioexception {      newfile.mkdirs();     file[] files = dropboxfile.listfiles();      (file file : files) {         if (file.isdirectory()) {             copydirectory(file, new file(newfile, file.getname()));          } else {             copyfile(file, new file(newfile, file.getname()));         }     } }   public static final void copyfile(file source, file destination) throws ioexception {     filechannel sourcechannel = new fileinputstream(source).getchannel();     filechannel targetchannel = new fileoutputstream(destination).getchannel();     sourcechannel.transferto(0, sourcechannel.size(), targetchannel);     sourcechannel.close();     targetchannel.close(); } 

you can dropbox file following:

file dropboxfile = new file(root_to_dropbox_file, file_name); 

and new file under sd card can created following:

string root = environment.getexternalstoragedirectory().tostring(); file newfile = new file(root + "/selected_name");      

last not least add following permissions android manifest file:

<uses-permission android:name="android.permission.write_external_storage" />  <android:uses-permission     android:name="android.permission.read_external_storage"     android:maxsdkversion="18"/> 

Comments