我尝试将文件从其他包“/data/data/targetPackage”复制到“/data/data/myPackate”,但它不起作用。我有请求su
权限
p = Runtime.getRuntime().exec("su");
// Attempt to write a file to a root-only
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("chmod 777 /data/data/targetPackage/databases"+"\n");
// Close the terminal
os.writeBytes("exit\n");
os.flush();
try
{
p.waitFor();
if (p.exitValue() != 255)
{
// TODO Code to run on success
toastMessage("root");
//accsessDB();
}
else
{
// TODO Code to run on unsuccessful
toastMessage("not root");
}
}
catch (InterruptedException e)
{
// TODO Code to run in interrupted exception
toastMessage("not root");
}
和这个代码副本
File f=new File("/data/data/targetPackage/databases/targetFile");
InputStream input = new FileInputStream(f);
new File("/data/data/myPackate/databases").mkdir();
File f2=new File("/data/data/myPackate/databases/targetFile");
OutputStream output = new FileOutputStream(f2,true);
byte[] buf= new byte[1024];
toastMessage(Integer.toString(input.read(buf)));
int len;
while((len=input.read(buf))>0)
{
output.write(buf, 0,len);
}
output.close();
input.close();
请帮我