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;
}
Android展示本地图片
最新推荐文章于 2023-07-25 17:10:39 发布