Android 根目录获取文件遍历 /*** 通过反射调用获取内置存储和外置sd卡根路径(通用)** param mContext 上下文* param is_removale 是否可移除false返回内部存储路径true返回外置SD卡路径* return*/private String getStorage0Path(Context mContext, boolean is_removale) {String path ;//使用getSystemService(String)检索一个StorageManager用于访问系统存储功能。StorageManager mStorageManager (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);Class? storageVolumeClazz null;try {storageVolumeClazz Class.forName(android.os.storage.StorageVolume);Method getVolumeList mStorageManager.getClass().getMethod(getVolumeList);Method getPath storageVolumeClazz.getMethod(getPath);Method isRemovable storageVolumeClazz.getMethod(isRemovable);Object result getVolumeList.invoke(mStorageManager);for (int i 0; i Array.getLength(result); i) {Object storageVolumeElement Array.get(result, i);path (String) getPath.invoke(storageVolumeElement);boolean removable (Boolean) isRemovable.invoke(storageVolumeElement);if (is_removale removable) {return path;}}} catch (Exception e) {e.printStackTrace();}return path;}遍历文件夹public static VectorString getFileName(String fileAbsolutePath) {VectorString vecFile new VectorString();File file new File(fileAbsolutePath);File[] subFile file.listFiles();for (int iFileLength 0; iFileLength subFile.length; iFileLength) {// 判断是否为文件夹if (!subFile[iFileLength].isDirectory()) {String filename subFile[iFileLength].getName();Log.e(eee,文件名 filename);}}return vecFile;}一.SDK的操作1、判断SD卡是否插入Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);这个在我之前做的东西中就非常有用因为涉及到SDK的读取自然就需要先判断SDK是否插入。2、获得sd卡根目录File skRoot Environment.getExternalStorageDirectory();二.私有目录下的文件操作1、获得私有根目录File fileRoot Context.getFilesDir()\;2.文件夹或文件夹操作1获得文件夹和文件路径a.获得文件或文件夹的绝对路径和相对路径。区别String path File.getPath();//相对String path File.getAbsoultePath();//绝对b.获得文件或文件夹的父目录String parentPath File.getParent();c.获得文件或文件夹的名称String Name File.getName();(2)建立文件或文件夹File.mkDir(); //建立文件夹File.createNewFile();//建立文件(3)判断是文件或文件夹File.isDirectory()File.isDirectory()(4)列出文件夹下的所有文件和文件夹名File[] files File.listFiles();(5)修改文件夹和文件名File.renameTo(dest);(6)删除文件夹或文件File.delete();

相关新闻

最新新闻

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现 【免费下载链接】serenity The Serenity Operating System 🐞 项目地址: https://gitcode.com/GitHub_Trending/se/serenity 导读 本文以 getopt(3) 手册 为核心&a…

2026/9/29 2:52:50
轻量服务器还是ECS?大促云服务器选购与避坑实战指南

轻量服务器还是ECS?大促云服务器选购与避坑实战指南

每年大促节点,群里永远有人在问同一个问题:“38元的轻量服务器到底怎么抢?为什么我每次点进去都是已售罄?68元直购和99元的ECS我到底选哪个?”作为一个常年帮团队和自己采购云服务器的老用户,我太清楚这种纠…

2026/9/29 2:52:51
为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南 【免费下载链接】agents Multi-harness agentic plugin marketplace for Claude Code, Codex, Cursor, OpenCode, GitHub Copilot, and Google Antigravity 项目地址:…

2026/9/29 1:29:30
PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署 【免费下载链接】PaddleOCR Turn any PDF or image document into structured data for your AI. A powerful, lightweight OCR toolkit that bridges the gap between i…

2026/9/29 1:39:24
Spring源码解析:构造器注入的类型转换与候选匹配机制

Spring源码解析:构造器注入的类型转换与候选匹配机制

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/9/29 22:57:57
openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由 【免费下载链接】openai-agents-python A lightweight, powerful framework for multi-agent workflows 项目地址: https://gitcode.com/GitHub_Trending/op/openai-agents-pyth…

2026/9/29 2:52:53

日新闻

周新闻