遍历过程不知道哪出错了,也没捕获到异常。 public static void addFileToJson(String filePath, JSONObject json) {
try {
File file = new File(filePath);
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
JSONObject jsonObj = new JSONObject();
json.put(files[i].getName(), jsonObj);
jsonObj.put("Time", (files[i].lastModified()));
if (files[i].isDirectory()) {
jsonObj.put("isDir", true);
addFileToJson(files[i].getPath(), jsonObj);
} else {
jsonObj.put("isDir", false);
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
下面是调用
JSONObject json = new JSONObject();
JSONObject root = new JSONObject();
json.put("存储卡", root);
root.put("isDir", true);
addFileToJson("/sdcard/", root);
try {
File file = new File(filePath);
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
JSONObject jsonObj = new JSONObject();
json.put(files[i].getName(), jsonObj);
jsonObj.put("Time", (files[i].lastModified()));
if (files[i].isDirectory()) {
jsonObj.put("isDir", true);
addFileToJson(files[i].getPath(), jsonObj);
} else {
jsonObj.put("isDir", false);
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
下面是调用
JSONObject json = new JSONObject();
JSONObject root = new JSONObject();
json.put("存储卡", root);
root.put("isDir", true);
addFileToJson("/sdcard/", root);
解决方案 »
- Android摄像(录像)功能能做变焦吗,怎么做啊
- 为launcher添加一个仿Mac的dock(附源码)
- 关于通知栏以及动态数据的问题
- android擦除动画如何实现
- 在view中如何实现bitmap的旋转?
- 请教android中有类似hook功能的函数吗?
- 关于res/layout/main.xml的问题?
- No resource identifier found for attribute 'minSdVersion' in package 'android'
- __________________________________________________android报表,统计图。
- 编写一个算法,实现1024位二进制数据的加减操作
- android 和 嵌入式的关系
- apk的安装原理或实现?
最好的办法是在主线程中在开个线程