
Untitled
By: a guest on
May 22nd, 2012 | syntax:
None | size: 1.14 KB | hits: 37 | expires: Never
Android - Can not find the file although it exists in the data folder?
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "\data\PackageName\databases\myDB.db";
String backupDBPath = "myDB.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists())
{
// code to copy from currentDB to backupDB
}
}
} catch (Exception e) {
}
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
try
{
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "\data\PackageName\databases\myDB";
String backupDBPath = "myDB";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists())
{
// code to copy from currentDB to backupDB
}
}
} catch (Exception e) {
}