无法将数据导出到SD卡中

时间:2018-06-19 09:08:30

标签: android

我想通过点击将我的应用程序中的数据导出到SD卡,我正在执行以下功能,但我无法做到这一点。它不会执行if语句,并且它会在不执行的情况下退出循环。

private void exportDB() {
    try {

        File data = Environment.getDataDirectory();
        File sd=new File("/storage/9016-4EF8/ppt");

        if (sd.canWrite()) {

            File currentDBPath = getDatabasePath(Constants.DB_NAME);
                    String backupDBPath = "ppt";

            File backupDB = new File(sd, backupDBPath);

            FileChannel src = new FileInputStream(currentDBPath).getChannel();
            FileChannel dst = new FileOutputStream(backupDB).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();
            Toast.makeText(getApplicationContext(), "Backup Successful!",
                    Toast.LENGTH_SHORT).show();

        }
    } catch (Exception e) {

        Toast.makeText(getApplicationContext(), "Backup Failed!", Toast.LENGTH_SHORT)
                .show();
    }
}

我是新手并使用sqlite开发应用程序

0 个答案:

没有答案