您的位置:首页 > 移动开发 > Android开发

android 从指定的位置得到指定文件名的文件

2011-11-01 11:40 218 查看
private List<String> getImagesFromSD() {

List<String> imageList = new ArrayList<String>();

File f = new File("/sdcard/");

if (Environment.getExternalStorageState().equals(

Environment.MEDIA_MOUNTED)) {

Log.i(TAG, "===environment=="+Environment.getExternalStorageDirectory().toString());

f = new File(Environment.getExternalStorageDirectory().toString());

} else {

Toast.makeText(ACDsee.this, R.string.sdcarderror, 1).show();

return imageList;

}

File[] files = f.listFiles();

if (files == null || files.length == 0)

return imageList;

/**

* 将所有图像文件的路径存入ArrayList列表

*/

for (int i = 0; i < files.length; i++) {

file = files[i];

if (isImageFile(file.getPath())){

imageList.add(file.getPath());

Log.i(TAG, "==="+file.getPath());

}

}

return imageList;

}

/**

* @param fName

* @return

*/

private boolean isImageFile(String fName) {

boolean re;

String end = fName

.substring(fName.lastIndexOf(".") + 1, fName.length())

.toLowerCase();

/**

* 依据文件扩展名判断是否为图像文件

*/

if (end.equals("jpg") || end.equals("gif") || end.equals("png")

|| end.equals("jpeg") || end.equals("bmp")) {

re = true;

} else {

re = false;

}

return re;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐