• Android操作sd卡


    // 判断sd卡是否存在
            boolean sdCardExist = Environment.getExternalStorageState().equals(
                    android.os.Environment.MEDIA_MOUNTED);
            // 获得sd卡根目录
            if (sdCardExist) {
                File dir = Environment.getExternalStorageDirectory();
                String path = dir.getAbsolutePath() + "/麻城市宅基地资料/";
                ArrayList<String> folder = getFolder(path);
                listParents = listParent(folder);
            }

    ------------------------

        // List转换为String[]
        public String[] listParent(ArrayList<String> list) {
            int size = list.size();
            String[] array = new String[size];
            for (int i = 0; i < list.size(); i++) {
                array[i] = (String) list.get(i);
            }
            return array;
        }
    
        // 检查文件夹是否存在
        boolean isFolderExists(String strFolder) {
            File file = new File(strFolder);
            return file.exists();
        }
    
        // 扫描文件夹目录下的文件夹名字
        public ArrayList<String> getFolder(String path) {
            ArrayList<String> names = new ArrayList<String>();
            File file = new File(path);
            if (file.isDirectory()) {
                File[] array = file.listFiles();
                for (int i = 0; i < array.length; i++) {
                    File f = array[i];
                    names.add(f.getName());
                    System.out.println("文件夹名称" + f.getName());
                }
            }
            return names;
    
        }
    
        // 扫描文件夹里面的数据
        public ArrayList<String> folderScan(String path) {
            File file = new File(path);
            ArrayList<String> names = new ArrayList<String>();
            if (file.isDirectory()) {
                File[] array = file.listFiles();
    
                for (int i = 0; i < array.length; i++) {
                    File f = array[i];
    
                    if (f.isFile()) {// FILE TYPE
                        String name = f.getName();
                        if (name.contains(".jpg")) {
                            names.add(name);
                            fileScan(f.getAbsolutePath());
                        }
                    } else {// FOLDER TYPE
                        folderScan(f.getAbsolutePath());
                    }
                }
            }
            return names;
        }
    
        // 扫描
        public void fileScan(String file) {
            Uri data = Uri.parse("file://" + file);
            sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, data));
        }
        // 重命名文件
        public void renameFloder(String floerName, String reName) {
            File file = new File(floerName);
            System.out.println("-->" + file.toString());
            System.out.println("-->" + rename);
            file.renameTo(new File(reName));
        }
  • 相关阅读:
    yarn 0.9.0 build spark
    redhat6.4上build storm 0.9.0.1
    redhat6.4安装storm集群-4节点
    Hadoop 2.2.0 4结点集群安装 非HA
    redhat6.4上安装mysql
    redhat6.4上用apache建立os repos
    Hive Over HBase
    Hadoop 2.2.0学习笔记20131210
    Hadoop 2.2.0学习笔记20131209
    IDH2.5.1. Pain Points
  • 原文地址:https://www.cnblogs.com/spadd/p/4424705.html
Copyright © 2020-2023  润新知