在Android的访问/ data文件夹中的文件 [英] Access /data folder files in android
本文介绍了在Android的访问/ data文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经根植我的设备,我有安装的busybox。现在,我想通过我的application.My应用程序访问/ data文件夹中的文件有超级用户权限,但我仍无法访问文件 任何人能知道如何做到这一点(有或没有的busybox)
请帮我 在此先感谢
code:
IF((新文件(/数据/斌/苏))。存在())
SU_COMMAND =/数据/斌/苏;
其他
SU_COMMAND =苏;
字符串命令1 =busybox的安装/ SD卡\ N的;
字符串命令2 =busybox的安装/ SYSTEM \ N的;
字符串命令=busybox的CP /data/data/com.my.test.app/databases/到/ mnt / SD卡/ testapp / \ N的;
工艺过程=(新的ProcessBuilder(AS))开始()。
运行时室温=调用Runtime.getRuntime();
java.io.OutputStream中的OutputStream = process.getOutputStream();
outputstream.write(command1.getBytes());
outputstream.flush();
解决方案
试试这个:
私人布尔运行(布尔runAsRoot,串CMD){
字符串的shell = runAsRoot? 苏:sh的;
INT退出code = 255;
进程p;
尝试 {
P =调用Runtime.getRuntime()EXEC(壳);
DataOutputStream类OS =新DataOutputStream类(p.getOutputStream());
os.writeBytes(CMD +\ N);
os.flush();
os.writeBytes(退出\ n);
os.flush();
退出code = p.waitFor();
}赶上(IOException异常E1){
Log.e(异常,e1.toString());
}赶上(InterruptedException异常E){
Log.e(异常,e.toString());
}
返程(退出code = 255!);
}
公共布尔的CopyFile(){
返回运行(真的,busybox的CP /data/data/com.my.test.app/databases/到/ mnt / SD卡/ testapp /);
}
I have rooted my device and I have install busybox. Now I want to access /data folder files through my application.My application have super user permissions but still i am not able to access file Can any one know how to do this (with or without busybox)
please help me Thanks in advance
Code:
if ((new File("/data/bin/su")).exists())
SU_COMMAND = "/data/bin/su";
else
SU_COMMAND = "su";
String command1 = "busybox mount /sdcard \n";
String command2 = "busybox mount /system \n";
String command = "busybox cp /data/data/com.my.test.app/databases/ /mnt/sdcard/testapp/ \n";
Process process = (new ProcessBuilder(as)).start();
Runtime rt = Runtime.getRuntime();
java.io.OutputStream outputstream = process.getOutputStream();
outputstream.write(command1.getBytes());
outputstream.flush();
解决方案
Try out this one:
private boolean run(boolean runAsRoot, String cmd) {
String shell = runAsRoot ? "su" : "sh";
int exitCode = 255;
Process p;
try {
p = Runtime.getRuntime().exec(shell);
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes(cmd + "\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
exitCode = p.waitFor();
} catch (IOException e1) {
Log.e("Exception", e1.toString());
} catch (InterruptedException e) {
Log.e("Exception", e.toString());
}
return (exitCode != 255);
}
public boolean copyFile() {
return run(true, "busybox cp /data/data/com.my.test.app/databases/ /mnt/sdcard/testapp/");
}
这篇关于在Android的访问/ data文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文