lundi 27 juillet 2015

Android how to solve open failed:ENOENT(No such file or directory) error?

I have an option to backup the SQLite Database of my app by using following code snippet.

 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();
                        }

It previously worked fine but whenever I tried to backup the Database it shows the following error. /data/data/com.realtech.latlngrecorder/databases/latLngDb:open failed: ENOENT(No such file or directory) I don't know what went wrong now. Above code worked very well previously. Any Solutions. Thank you.

Aucun commentaire:

Enregistrer un commentaire