Android File.listFiles does not display all files inside a directory

I am using Android Emulator 2.2 to develop a small application. I have to list all image file files (jpg) in the directory. I copied the files to "/ data" using the paash ADB command.

Example: /data/1.jpg

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

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

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

But strangely enough, if I create an ImageView with a hard-coded path "/data/1.jpg", I could see how the image is drawn.

Can someone help me .... where there might be a 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 a filenamefilter that accepts only files with the jpg extension. But if I set a breakpoint in the imFilter code, the breakpoint will not fall into the event.

 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 
+4
source share
1 answer

I study this code and see that the problem is in resolution. As you can see below, you cannot read this dir.Find another directory for collecting 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 what you can see from the ls -l command. explain what it means

+3
source

All Articles