3

Path name is : /storage/emulated/0/Xender/video/MyVideo.mp4

I am able to get last file name [MyVideo.mp4] from path using

String path="/storage/emulated/0/Xender/video/MyVideo.mp4"; String filename=path.substring(path.lastIndexOf("/")+1); 

https://stackoverflow.com/a/26570321/5035015

Now i want to extract path [/storage/emulated/0/Xender/video] from this path.

I have one use of this path in my code so that i want to do this like this.

How can i do this?

Any help will be appreciated.

0

1 Answer 1

10

new File(path).getParentFile().getName() should work.

With regards to your current code, don't implement your own path parser. Use File.

Also note that this has nothing to do with Android specifically; this is a general Java question.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.