Java – Gets the directory for the file

Gets the directory for the file… here is a solution to the problem.

Gets the directory for the file

I

think I have a simple question, but I can’t figure it out. The directory where I want to get the files.

Example:
path =/mnt/sdcard/music/music.mp3

“Music” should be returned

public String getDir(String pathAudioFile)
{
    File f = new File(pathAudioFile);

return  f.???
}

Solution

f.getParent();  returns directory String
f.getParentFile();  returns File directory object

Related Problems and Solutions