如何显示存储到 SD 卡中的文件名的某些部分,我正在开发相机应用程序,在其中捕获照片并存储到 SD 卡中,如下所示:
AU_201403251160_4_7_B-4-7-001.jpg
现在我将所有存储的图像显示到列表中,并且我只需要显示以下代码作为文件名,而不是 AU_201403251160_4_7_B-4-7-001.jpg :
B-4-7-001.jpg
代码:
// ColImgName
TextView txtName = (TextView) convertView.findViewById(R.id.ColImgName);
strPath = ImageList.get(position).toString();
// Get File Name
fileName = strPath.substring( strPath.lastIndexOf('/')+1, strPath.length() );
file = new File(strPath);
最佳答案
String[] a = "AU_201403251160_4_7_B-4-7-001.jpg".split("_");
System.out.println(a[a.length - 1]);
输出:
B-4-7-001.jpg
这是最小的,您显然需要进行一些检查。
关于java - 如何显示文件名的某些部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22685177/