我已经在我的设备上安装了一个应用程序。但我想将该数据库复制到我的应用程序使用的SD卡。我用这段代码来复制数据库。但它失败了。并需要“su”命令
public void copydatabase() throws IOException{
String [] cmd1 = { "su", "cp", "/data/data/com.apps/databases/data01.db", "/mnt/extSdCard/data01.db"};
Process process = new ProcessBuilder(cmd1).start();
try {
process.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
没有“su”命令将任何一些代码复制到SDCard?
答案 0 :(得分:0)
public static void copyDataBase(Context mActivity) throws IOException {
InputStream myInput = new FileInputStream(
new File("/data/data/" + mActivity.getPackageName()
+ "/databases/" + "xyz.sqlite"));
File files = new File("/sdcard/files/");
files.mkdirs();
String outFileName = "/sdcard/files/xyz.sqlite";
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int bufferLength;
while ((bufferLength = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, bufferLength);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
我希望它对你有用......