Tutorial :Android File.listFiles does not show all the files inside the directory


I am using Android Emulator 2.2 version to develop a small application. I am supposed to list all the image files(jpg) files under a directory. I copied the files to "/data" through ADB puash command.

Example : /data/1.jpg

Now I create a File object with the directory path as input and call listFiles api.

File dir = new File(dirPath);  File[] filelist = dir.listFiles();  

But the fileList does not contain the image file(1.jpg).

But strangely, If I create a ImageView with hardcoded path "/data/1.jpg", I could see the image getting drawn.

Can some one help me.... where could be the problem

Thanks, Kowndinya

public int PopulateList(final String dirPath)  {      m_CurrentDirectory = new File(dirPath);      _namelist.clear();      _pathlist.clear();        File[] fileList = m_CurrentDirectory.listFiles(imFilter);      if (fileList != null)      {          for ( int i = 0;i<fileList.length;i++)          {              _namelist.addElement(fileList[i].getName());              _pathlist.addElement(fileList[i].getAbsolutePath());           }      }      notifyDataSetChanged();      return 0;  }  

imFilter is an filenamefilter that accepts only files with jpg extension. But if I put break point in the imFilter code, break point does not event hit.

Output of adb shell ls -l /data:  ------------------------------------  drwxrwx--t system   misc              2010-08-05 15:32 misc  drwxrwx--x shell    shell             2010-08-05 15:32 local  drwxrwx--x system   system            2010-08-05 15:32 app-private  drwx------ system   system            2010-08-05 15:34 backup  drwx------ root     root              2010-08-05 15:34 property  drwxrwx--x system   system            2010-08-05 15:35 data  -rw-rw-rw- root     root        75752 2010-03-30 12:26 zona_ind_012.jpg  drwxrwx--x system   system            2010-08-05 16:16 app  drwxr-x--- root     log               2010-08-05 15:32 dontpanic  drwxrwx--x system   system            2010-08-05 16:25 dalvik-cache  drwxrwxr-x system   system            2010-08-05 17:16 system  drwxrwx--- root     root              2010-08-05 15:32 lost+found  


I explore that code, and see, trouble is in permission. As you can see below, you can't read that dir.Find another dir to collect your files.

**Can read dir:**   /dev =true  /root =false  /data =false  /default.prop =true  /init =false  /init.rc =false  /proc =true  /sbin =false  /sys =true  /system =true  /etc =true  /d =false  /mnt =true  /acct =true  /sdcard =true  /cache =false  /config =false  

and that you can see from "ls -l" command. explain what does mean

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »