我有一个复制和修改文件权限的应用程序。但是当我尝试阅读所述文件时,我得到了许可被拒绝。
java.io.FileNotFoundException:/data/data/com.lstupenengo.primeraapp/files/xx:open failed:EACCES(Permission denied)
我怎么知道RootTools何时完成?
我的代码:
RootTools.copyFile("/data/data/com.xxx/" + file, getFilesDir() +"/"+ file, true, false);
CommandCapture cmd = new CommandCapture(0,"chmod 777 "+getFilesDir()+"/"+file);
try {
RootTools.getShell(true).add(cmd);
} catch (TimeoutException | RootDeniedException | IOException e) {
e.printStackTrace();
Log.e("Root "+file, "Fallo");
}
File fts = new File(getFilesDir()+"/"+file);
FileInputStream fis = new FileInputStream(fts); //Here I get my error.
logcat的
12-18 16:23:41.874 30092-30806/com.lstupenengo.primeraapp W/System.err﹕ java.io.FileNotFoundException: /data/data/com.lstupenengo.primeraapp/files/xx: open failed: EACCES (Permission denied)
12-18 16:23:41.874 30092-30806/com.lstupenengo.primeraapp W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:418)
12-18 16:23:41.874 30092-30806/com.lstupenengo.primeraapp W/System.err﹕ at java.io.FileInputStream.<init>(FileInputStream.java:78)
12-18 16:23:41.874 30092-30806/com.lstupenengo.primeraapp W/System.err﹕ at com.lstupenengo.primeraapp.myFTP.upload(myFTP.java:80)
12-18 16:23:41.874 30092-30806/com.lstupenengo.primeraapp W/System.err﹕ at com.lstupenengo.primeraapp.FirstRunService.upload(FirstRunService.java:75)
12-18 16:23:41.874 30092-30806/com.lstupenengo.primeraapp W/System.err﹕ at com.lstupenengo.primeraapp.FirstRunService.onHandleIntent(FirstRunService.java:47)
答案 0 :(得分:0)
添加了此代码,现在我获得了Chmod的豁免,但它确实有效。
CommandCapture cmd = new CommandCapture(0,"chmod 777 "+getApplicationInfo().dataDir+"/databases/"+file);
try {
RootTools.getShell(true).add(cmd);
while (!cmd.isFinished()) {
synchronized (cmd) {
try {
if (!cmd.isFinished()) {
cmd.wait(100);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
} catch (TimeoutException | RootDeniedException | IOException e) {
Log.e(file, "Chmod fail");
e.printStackTrace();
}