0

I am trying to display the contents of /data/dalvik-cache through the following program but it returns a NULL pointer exception. After a bit googling i found out that i don't have permissions to read the contents of /data folder.My phone is rooted and is there a way to display the contents of all such folders whose permissions are limited?

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        File listfiles[] = null;
        final String s = "/data/dalvik-cache";

        File aDirectory = new File("/mnt");

        if(aDirectory.isDirectory())
            listfiles = aDirectory.listFiles();

        for(int i=0;i<listfiles.length;i++)
            Log.i("FileName", listfiles[i].getName());

    }
nikhil
  • 9,023
  • 22
  • 55
  • 81

2 Answers2

1

I work on directory picker code. To list a dir content use:

File f = new File("/cashe");
String[] d = f.list();

Result is null. Other dir it work fine.

Yury Finchenko
  • 1,035
  • 13
  • 19
0

You have to run shell or other program via su command (e.g. with root privileges). You can see an example here.

Community
  • 1
  • 1
trashkalmar
  • 883
  • 5
  • 11