zoukankan      html  css  js  c++  java
  • 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));
        }
  • 相关阅读:
    ping
    android Handler总结
    配置网络测试环境的批处理
    shell 的选项解析
    [转] Linux 中共享库的搜索
    SecureCRT 脚本一则(0720.Rev.1)
    使用 Wget 完成自动 Web 认证(推 portal)
    shell 选项解析之需求一:多路径自动补全
    getopts 的简单模拟(09.12 Rev)
    ThinkPHP框架使用心得三 RBAC权限控制(2)简要原理
  • 原文地址:https://www.cnblogs.com/spadd/p/4424705.html
Copyright © 2011-2022 走看看