path example: /data/aaa/bbb/xxx.txt
File file = new File(filePath); File parentFile = file.getParentFile(); String directoryName = parentFile.getAbsolutePath().substring(parentFile.getAbsolutePath().lastIndexOf("/")+1, parentFile.getAbsolutePath().length());