How to get file name from file path in android How to get file name from file path in android android android

How to get file name from file path in android


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);


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


The easiest solution is to use Uri.getLastPathSegment():

String filename = uri.getLastPathSegment();