String path = Environment.getExternalStorageDirectory().getAbsolutePath();
File fileTest= new File(path + "/fileTest");
private List<File> list = new ArrayList<>();
list.clear();
list = getFile(fileTest);
if (list .size() == 1){
FileInputStream fs = null;
try {
fs = new FileInputStream(fileTest+ "/" + list.get(0).getName());
Bitmap bitmap = BitmapFactory.decodeStream(fs);
fs.close();
mImageView1.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.e("fileTest", "读取本地文件失败:" + e.getLocalizedMessage());
} catch (IOException e) {
e.printStackTrace();
}
}
public static List<File> getFile(File file) {
List<File> list = new ArrayList<>();
File[] fileArray = file.listFiles();
if (fileArray == null) {
return null;
} else {
for (File f : fileArray) {
if (f.isFile()) {
list.add(0, f);
} else {
getFile(f);
}
}
}
return list;
}
02-09
4450
02-11
8979
07-02
08-20
5724
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交