zoukankan      html  css  js  c++  java
  • search a file from directory and get storage directorys from android device(i use tablet here)

    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;
        }
    
    }
  • 相关阅读:
    19凡路国庆小作业的题解集合(qwq只是我出的题,我会标明出处的)
    一个for打印99乘法表(这是一种实现方式,可以多种方式的)
    采访学长所得
    洛谷P1028 数的计算
    ccf 2019_03_2 二十四点
    ccf 201812-1 小明上学
    洛谷P3387 【模板】缩点
    洛谷P3216 [HNOI2011]数学作业
    洛谷P1471 方差
    HDU 4114 Disney's FastPass
  • 原文地址:https://www.cnblogs.com/slider/p/2982975.html
Copyright © 2011-2022 走看看