我在路徑上的內部存儲器上有一個文件,例如/data/data/<package name>/folder/myfile
我沒有訪問此文件的權限,但對於我的實現,我必須讀取此文件。爲此,我首先對該文件運行su
命令,並通過chmod
命令將該權限設置爲777
,然後嘗試訪問該文件。但仍顯示該文件不存在。請告訴我如何才能讓這個文件讀取。從沒有讀/寫權限的內部存儲讀取文件?
以下是我正在嘗試做的事情。
public void runChmodAndSU(String filePath)
{
Process chperm;
try {
chperm = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(chperm.getOutputStream());
os.writeBytes("chmod 777 "+ filePath +"\n");
os.writeBytes("exit\n");
os.flush();
chperm.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
上面的代碼運行後我檢查一下這樣說:
File myFile = new File(filePath);
if (myFile.exists())
{
Log.e("Success!", "myFile Exists");
}
else {
Log.e("Failure!", "myFile Does not Exists");
}
請告訴我,我怎麼能讀這個非常文件。有沒有其他的方式來訪問你沒有權限的文件?
這是你的應用程序創建的文件嗎? – TronicZomB
@TronicZomB no ..它是來自我的另一個應用程序的文件。 –
好的,不太瞭解它的那一面,然後...... – TronicZomB