Pages

Subscribe:

Labels

Wednesday, 28 September 2011

Get Files from SDcard

To do this we need to get the root directory of the external storage directory, i.e SDcard.

File f = new File("/sdcard");
private List<String> item = new ArrayList<String>();
private List<String> path = new ArrayList<String>();
getFiles(f);
The getFiles(..) method retrieves the all files from the sdcard and stores
    

private void getFiles(File f)
    {
        File[] files=f.listFiles();
        for (int i = 0; i < files.length; i++)
        {
            try{
                if (files[i].isDirectory()) {
                    getFiles(files[i]);
                }
                else
                {
                    if (files[i].isFile() ) {
                        if(files[i].getParent().equals("/sdcard/DCIM/.thumbnails"))
                            continue;
                        String test=files[i].getName().toLowerCase();
                        if(test.endsWith(".mp3")||test.endsWith(".mp4")||test.endsWith(".3gp")||test.endsWith(".wav")||test.endsWith("flac")||test.endsWith("xmf")||test.endsWith("ota"))
                        {
                            path.add(files[i].getPath());
                            item.add(files[i].getName());
                        }
                    }
                }
            }catch(Exception e){
                 e.getMessage();
            }
        }   
    }//get files

1 comment:

Petter Marry said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.

Post a Comment