获取sdcard文件

权限:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />

 

// ------------------获取sdcard信息------------------------------

	private void readFile() {
		File file = Environment.getExternalStorageDirectory();
		File[] files = file.listFiles();
		readFile(files);
	}

	private void readFile(File[] files) {
		if (files != null && files.length > 0) {
			for (int i = 0; i < files.length; i++) {
				// if (files[i].isDirectory()) {
				// readFile(files[i].listFiles());
				// } else {
				parseFile(files[i]);
				// }
				if (i == files.length - 1) {
				}
			}
		}

	}

	private void parseFile(File file) {
		String fileName = file.getName();
		String filePath = file.getPath();
		Map<String, String> map = new HashMap<String, String>();
		map.put("fileName", fileName);
		map.put("filePath", filePath);
		data.add(map);
	}
 

你可能感兴趣的:(sdcard)