我在路径上的内部存储器上有一个文件,例如/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