Android如何解决打开失败:ENOENT(没有这样的文件或目录)错误?

时间:2015-07-28 04:17:18

标签: android sqlite

我可以选择使用以下代码段备份我的应用的SQLite Database

 File sd = Environment.getExternalStorageDirectory();
                        File data = Environment.getDataDirectory();
                        File myDir = new File(Environment.getExternalStorageDirectory(), "LatLng Recorder");
                        if (!myDir.exists()) {
                            myDir.mkdir();
                        }
                        FileChannel source = null;
                        FileChannel destination = null;
                        String currentDbPath = "/data/" + "com.realtech.latlngrecorder" + "/databases/" + "latLngDB";
                        String backupPath = "/LatLng Recorder/latLngDB.db";

                        File currentDb = new File(data, currentDbPath);
                        File backupDb = new File(sd, backupPath);
                        try {
                            source = new FileInputStream(currentDb).getChannel();
                            destination = new FileOutputStream(backupDb).getChannel();
                            destination.transferFrom(source, 0, source.size());
                            source.close();
                            destination.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }

以前工作正常,但每当我尝试备份数据库时,它都会显示以下错误。 /data/data/com.realtech.latlngrecorder/databases/latLngDb:open failed: ENOENT(No such file or directory) 我现在不知道出了什么问题。上面的代码工作得非常好。任何解决方案谢谢。

0 个答案:

没有答案