开发者

Can not access android /data folder?

  try {
     Runtime rt = Runtime.getRuntime();
     Process pcs = rt.exec("ls -l /data");
     BufferedReader br = new BufferedReader(new InputStreamReader(pcs
           .getInputStream()));
     String line = null;
     while ((line = br.readLine()) != null) {
        Log.e("line","line="+line);
     }
     br.close();
     pcs.waitFor(开发者_运维技巧);
     int ret = pcs.exitValue();
     Log.e("ret","ret="+ret);
  } catch (Exception e) {
     Log.e("Exception", "Exception", e);
  }

only print "ret=0",How to print the correct path?


Android protects it's internal directories. You can only access your directory under /data/data/your_package. I believe that the normal user does not have Read privileges for the /data directory on a normal device.


data folder is inaccessible on a device except by system processes. You cannot access data folder of a unrooted phone through adb. You can access data folder of emulator or rooted phones.


Did you try doing it with your own app, and not by spawning another process (e.g. Runtime.exec())

File dataDir = new File("/data");

    String[] files = dataDir.list();

    for (int i = 0 ; i < files.length ; i++ ) {
        Log.d(TAG, "File: "+files[i]);
    }

Also, I'd look at the different read permissions, maybe there's another way to get to the data you're looking for via ContentProviders.


If you'll want to access /data folder not from java code, but from your PC console - you can use a adb shell command. it has no restrictions.

remember to have an emulator running, or connect your phone via USB before running that

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜