我已经实现了用于拆分文件路径并在文本视图中获取实际文件名的 android 应用程序。当我运行应用程序时,它会显示文件路径中的所有字符串名称。我只想要一个文件名(introduction.ppt)。如何在文本视图中获取此文件名?
这是我的代码:
String path = "/mnt/sdcard/coverted/introduction.ppt";
String[] strAfterSpilt = path.split("/");
for(int j = 0; j < strAfterSpilt.length; j++) {
if(strAfterSpilt[j].length() > 0) {
String strFinalSplit = strAfterSpilt[j];
System.out.println("strFinalSplit :-> " + strFinalSplit);
function_arg1.setText(strFinalSplit);
} else { break; }
}
而且我必须尝试这种分割文件路径的方式;
String[] strAfterSpilt = path.split("/");
for (String str : strAfterSpilt) {
System.out.println("str" + str.lastIndexOf(strAfterSpilt[i]));
}