从rooted android手机上的/ data目录中读取文件时出错。 java.io.FileNotFoundException:open failed:EACCES(权限被拒绝)

时间:2015-12-08 14:47:30

标签: android android-sdcard

这是我的代码,我试图从我的root设备上的/ data目录访问文件。我的应用程序成功获得root权限,并且它可以访问其他文件夹(如/或/ sdcard或/ system等)中的数据。问题仅出现在/ data目录中。并且,我确定文件系统上存在这样的文件并获得正确的路径。如果文件不存在,则显示不同的错误。现在,我如何读取/ data目录中的文件?

try {

            File wifiConfFile = new File(Environment.getDataDirectory()+ File.separator + "system" + File.separator + "appops.xml");

            if(!wifiConfFile.exists()){
                Log.d("FILE", Environment.getDataDirectory()+"/system/appops.xml couldn't be loaded!");
            }
            fis = new FileInputStream(wifiConfFile);
            InputStreamReader isr = new InputStreamReader(fis);
            BufferedReader bufferedReader = new BufferedReader(isr);
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                sb.append(line);
            }
            wifiDesc.append(sb.toString());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

这是我的android-menifest文件中的权限块。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

而且,这是来自Android监视器......

12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: java.io.FileNotFoundException: /data/system/appops.xml: open failed: EACCES (Permission denied)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:456)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err:     at java.io.FileInputStream.<init>(FileInputStream.java:76)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err:     at rizanamic.wifipass.MainActivity.onCreate(MainActivity.java:71)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err:     at android.app.Activity.performCreate(Activity.java:5933)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err:     at android.app.ActivityThread.access$800(ActivityThread.java:144)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err:     at android.os.Looper.loop(Looper.java:135)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5229)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err:     at libcore.io.Posix.open(Native Method)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err:     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:442)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err:     ... 15 more

0 个答案:

没有答案