将数据库文件上载到Dropbox时找不到文件

时间:2013-09-17 05:50:15

标签: android database upload dropbox

我已经完成了一个Android应用程序并将DropBox集成到我的应用程序上传数据库。当我上传单个文件时,它将正确上传。我的问题是当我从我的应用程序获取db文件并将其上传到dropbox它显示文件未找到exeception。我也使用此链接但没有得到解决方案。 Link

FileInputStream inputStream = null;
             try {
                 String databasePath=getDatabasePath("databaseTaskApps.db").getPath();
                 Log.i(TAG,"DatabasePath:"+databasePath);
                 File file = new File(databasePath+ "/databaseTaskApps");
                 inputStream = new FileInputStream(file);

                 com.dropbox.client2.DropboxAPI.Entry newEntry = mApi.putFileOverwrite("/databaseTaskApps", inputStream,
                         file.length(), null);
                 Log.i("DbExampleLog", "The uploaded file's rev is: " + newEntry.rev);
             } catch (DropboxUnlinkedException e) {
                 // User has unlinked, ask them to link again here.
                 Toast.makeText(getApplicationContext(), "Not Uploading", Toast.LENGTH_SHORT).show();
             } catch (DropboxException e) {
                 Log.e("DbExampleLog", "Something went wrong while uploading.");
                 Toast.makeText(getApplicationContext(), "Not Uploading", Toast.LENGTH_SHORT).show();
             } catch (FileNotFoundException e) {
                 Log.e("DbExampleLog", "File not found.");
                 Toast.makeText(getApplicationContext(), "Not Uploading", Toast.LENGTH_SHORT).show();
             } finally {
                 if (inputStream != null) {
                     try {
                         inputStream.close();
                     } catch (IOException e) {
                     }
                 }
             }

1 个答案:

答案 0 :(得分:0)

  

Hai我找到了我的问题的答案

File[] files = new File("/data/data/com.dropbox.android.sample/databases/").listFiles(); 
            for (File f:files) {

                if (f.getName().equals("databaseTaskApps"))
                {
                    FileInputStream inputStream = null;
                    try {
                        inputStream = new FileInputStream(f);

                        com.dropbox.client2.DropboxAPI.Entry newEntry = mApi.putFileOverwrite("/databaseTaskApps", inputStream,
                                f.length(), null);
                        Log.i("DbExampleLog", "The uploaded file's rev is: " + newEntry.rev);
                    } catch (DropboxUnlinkedException e) {
                        // User has unlinked, ask them to link again here.
                     Toast.makeText(getApplicationContext(), "Not Uploading", Toast.LENGTH_SHORT).show();
                    } catch (DropboxException e) {
                        Log.e("DbExampleLog", "Something went wrong while uploading.");
                        Toast.makeText(getApplicationContext(), "Not Uploading", Toast.LENGTH_SHORT).show();
                    } catch (FileNotFoundException e) {
                        Log.e("DbExampleLog", "File not found.");
                        Toast.makeText(getApplicationContext(), "Not Uploading", Toast.LENGTH_SHORT).show();
                    } finally {
                        if (inputStream != null) {
                            try {
                                inputStream.close();
                            } catch (IOException e) {
                            }
                        }
                    }

                }
            }