android - restore database file from dropbox to local memory -
i have implemented database backup on dropbox, restore db dropbox internal memory (data\data\\database), think forbidden write directly, possible read stream file on dropbox, , open local file, clear data inside , , flush stream file? if yes, have code example?
i hope clear. code...
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 } byte[] buffer = new byte[4096]; dropboxinputstream fd = mapi.getfilestream (dbpath, null); br = new bufferedinputstream(fd, buffer.length); bw = new bufferedoutputstream(new fileoutputstream(localfile)); 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(); } { //in block: if (bw != null) { bw.close(); } if (br != null) { br.close(); } } return true; }
Comments
Post a Comment