I want to get file name from sdcard file path.
e.g. :/storage/sdcard0/DCIM/Camera/1414240995236.jpg I want get 1414240995236.jpg
I have written the code to fe
The easiest solution is to use Uri.getLastPathSegment():
String filename = uri.getLastPathSegment();
I think you can use substring method to get name of the file from the path string.
String path=":/storage/sdcard0/DCIM/Camera/1414240995236.jpg";
// it contains your image path...I'm using a temp string...
String filename=path.substring(path.lastIndexOf("/")+1);
Other Way is:
String[] parts = selectedFilePath.split("/");
final String fileName = parts[parts.length-1];
Simple and easy way to get File name
File file = new File("/storage/sdcard0/DCIM/Camera/1414240995236.jpg");
String strFileName = file.getName();
After add this code and print strFileName you will get strFileName = 1414240995236.jpg
FilenameUtils
to the rescue:
String filename = FilenameUtils.getName("/storage/sdcard0/DCIM/Camera/1414240995236.jpg");
We can find file name below code:
File file =new File(Path);
String filename=file.getName();