获取SD卡上的全部音频文件
2015-07-19 11:26
260 查看
getFiles("/sdcard/"); // 获取SD卡上的全部音频文件
1.
private void getFiles(String url) {
File files = new File(url); // 创建文件对象
File[] file = files.listFiles();//返回该路径下的所有完整路径的文件名
try {
for (File f : file) { // 通过for循环遍历获取到的文件数组
if (f.isDirectory()) { // 如果是目录,也就是文件夹
getFiles(f.getAbsolutePath()); // 递归调用
} else {
if (isAudioFile(f.getPath())) { // 如果是音频文件
audioList.add(f.getPath()); // 将文件的路径添加到list集合中
}
}
}
} catch (Exception e) {
e.printStackTrace(); // 输出异常信息
}
}
2.
private static String[] imageFormatSet = new String[] { "mp3", "wav", "3gp" }; // 合法的音频文件格式
// 判断是否为音频文件
private static boolean isAudioFile(String path) {
for (String format : imageFormatSet) { // 遍历数组
if (path.contains(format)) { // 判断是否为有合法的音频文件
return true;
}
}
return false;
}
1.
private void getFiles(String url) {
File files = new File(url); // 创建文件对象
File[] file = files.listFiles();//返回该路径下的所有完整路径的文件名
try {
for (File f : file) { // 通过for循环遍历获取到的文件数组
if (f.isDirectory()) { // 如果是目录,也就是文件夹
getFiles(f.getAbsolutePath()); // 递归调用
} else {
if (isAudioFile(f.getPath())) { // 如果是音频文件
audioList.add(f.getPath()); // 将文件的路径添加到list集合中
}
}
}
} catch (Exception e) {
e.printStackTrace(); // 输出异常信息
}
}
2.
private static String[] imageFormatSet = new String[] { "mp3", "wav", "3gp" }; // 合法的音频文件格式
// 判断是否为音频文件
private static boolean isAudioFile(String path) {
for (String format : imageFormatSet) { // 遍历数组
if (path.contains(format)) { // 判断是否为有合法的音频文件
return true;
}
}
return false;
}
相关文章推荐
- VMWare Workstation 443端口被占用
- php函数、类和对象以及类的封装、继承、类的静态方法、静态属性
- POJ 3740 Easy Finding
- Spring MVC快速入门笔记
- VC由进程ID获取窗口句柄
- Android Native Looper机制 - 监听文件描述符
- 数组中未出现的最小正整数
- 设计一个只能在堆上或栈上实例化的类
- 智能社区--HI3516C可视门禁研发出来咯
- [转]网站重复请求解决方案
- CF Gym 100187E Two Labyrinths (迷宫问题)
- javascript中mouseover、mouseout使用详解
- memset报传入的实参太多的错误
- [M0]Android Native层Looper详解
- 漫谈好程序员的标准
- node-inspector使用方法
- POJ 2676 Sudoku
- 一个简单结构体实现封装
- Android onClick 按钮单击事件 四种常用写法
- 12天学好C语言——记录我的C语言学习之路(Day 1)