如果您的设备未植根,您将无法访问应用程序的数据文件。尝试在您的任何文件中使用以下代码段Activity
将文件复制到 sdcard。
public static void copyDataFile() {
File dataDir = getFilesDir().getParentFile();
File target = new File(dataDir, "/* relative path to your sql file */");
File out = new File(Environment.getExternalStorageDirectory(), "/* new file name */");
copyFile(target, out);
}
public static void copyFile(File in, File out) {
if (in.exists()) {
if (!out.exists()) {
try {
out.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileInputStream is = null;
FileOutputStream os = null;
try {
is = new FileInputStream(in);
os = new FileOutputStream(out);
byte[] buf = new byte[4096];
int l = 0;
while ((l = is.read(buf)) > 0) {
os.write(buf, 0, l);
}
os.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (os != null) {
os.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}