有一个母文件夹ABC,母文件下有n个jpg图片和数个pdf文件和数个文件夹,现在想要
将所有的内容都展示出来,要如何实现
类似于如何的图片模式,里面图集的部分是图片,但无法展开
如何读取母文件夹内的子文件夹和其他类型的子文件
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 1000001000,,,, 2017-09-13 07:05关注
/**
- 获取指定目录内所有文件路径
- @param dirPath 需要查询的文件目录
-
@param _type 查询类型,比如mp3什么的
*/
public static JSONArray getAllFiles(String dirPath, String _type) {
File f = new File(dirPath);
if (!f.exists()) {//判断路径是否存在
return null;
}File[] files = f.listFiles();
if(files==null){//判断权限
return null;
}JSONArray fileList = new JSONArray();
for (File _file : files) {//遍历目录
if(_file.isFile() && _file.getName().endsWith(_type)){
String _name=_file.getName();
String filePath = _file.getAbsolutePath();//获取文件路径
String fileName = _file.getName().substring(0,_name.length()-4);//获取文件名
// Log.d("LOGCAT","fileName:"+fileName);
// Log.d("LOGCAT","filePath:"+filePath);
try {
JSONObject _fInfo = new JSONObject();
_fInfo.put("name", fileName);
_fInfo.put("path", filePath);
fileList.put(_fInfo);
}catch (Exception e){
}
} else if(_file.isDirectory()){//查询子目录
getAllFiles(_file.getAbsolutePath(), _type);
} else{
}
}
return fileList;
}
解决 无用评论 打赏 举报
悬赏问题
- ¥17 pro*C预编译“闪回查询”报错SCN不能识别
- ¥15 微信会员卡接入微信支付商户号收款
- ¥15 如何获取烟草零售终端数据
- ¥15 数学建模招标中位数问题
- ¥15 phython路径名过长报错 不知道什么问题
- ¥15 深度学习中模型转换该怎么实现
- ¥15 HLs设计手写数字识别程序编译通不过
- ¥15 Stata外部命令安装问题求帮助!
- ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
- ¥15 TYPCE母转母,插入认方向