Search a file from directory and get storage directorys from Android device (I use tablet here)

Source: Internet
Author: User
public class Explorer {    String TAG = "Explorer";    private final String DISK_DIR             = "/mnt";    public static final int DIR_SDCARD         = 0;     public static final int DIR_SDCARD_EX     = 1; // external sdcard    public static final int DIR_USB         = 2; // usb external storage        private static List<String> pathList = new ArrayList<String>();        public String getDiskPath(int typeDir) {        File[] files = new File(DISK_DIR).listFiles();        String filePath;        for (int i = 0; i < files.length; i++) {            filePath = files[i].getAbsolutePath().toLowerCase();            Log.d(TAG, "getDiskPath " + filePath);            switch (typeDir) {            case DIR_SDCARD:                if(filePath.equals("/mnt/sdcard"))                    return filePath;                break;            case DIR_SDCARD_EX:                if (filePath.contains("sdcard") && filePath.contains("ext")) {                    return filePath;                }                break;            case DIR_USB:                if(filePath.contains("usb"))                    return filePath;                break;            }        }        return null;    }        private void loadFileList(String dir, final String fileType) {        File fileDir = new File(dir);        if (fileDir.exists()) {            FilenameFilter filter = new FilenameFilter() {                public boolean accept(File dir, String filename) {                    File sel = new File(dir, filename);                    return filename.endsWith(fileType) || sel.isDirectory();                }            };            File[] files = fileDir.listFiles(filter);            if(files!=null){                for (File file : files) {                    String absolutePath = file.getAbsolutePath();                    if(file.isDirectory()){                        loadFileList(absolutePath, fileType);                    }else {                        pathList.add(absolutePath);                    }                }            }                    }    }        public List<String> getFileList(String dir, final String fileType){        loadFileList(dir, fileType);        return pathList;    }}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.