2011-05-10 43 views
0

我想显示完整路径的文件名。我得到完整的路径,但不知道如何获得扩展名的文件名? 请给我看一些例子。如何从路径中获取文件名

代码,我用它来获取文件的完整路径:

if (resultCode == Activity.RESULT_OK) { 
    Log.i("On onActivityResult", "get path"); 
    Uri selectedVideoUri = data.getData(); 
    try { 
     String filemanagerstring = selectedVideoUri.getPath(); 
      String selectedVideoPath = getPath(selectedVideoUri); 
     if (selectedVideoPath != null) { 
     filePath = selectedVideoPath; 
     Log.i("VideoFilePath", "" + filePath); 
     } else if (filemanagerstring != null) { 
     filePath = filemanagerstring; 
     Log.i("FilePath", "" + filePath); 
     } else { 
      Toast.makeText(getApplicationContext(), "Unknown path", 
          Toast.LENGTH_LONG).show(); 
      Log.e("Bitmap", "Unknown path"); 
      Log.i("FilePath", "" + filePath); 
     } 
+0

你用什么代码获取路径.....? – 2011-05-10 06:56:16

回答

1

试试这个

selectedVideoUri.getLastPathSegment() 
+0

这段代码的“1”响应表明什么? – Saurabh 2011-05-10 07:32:55

+0

意味着你有“1”..只是打印你的路径并检查。 – 2011-05-10 07:37:39

3

试试这个,其中path是整个文件名包括父目录:

​​