tags:

views:

46

answers:

3
  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?

+3  A: 

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.

NKijak
A: 

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.

Gubatron
A: 

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

zed_0xff