Reputation: 24998
So, I am trying to extract a path to a mp4 file from a URL. The problem is that they have parameters appended to it after a ?
.
Eg: www.example.com/video.mp4?w=1280&h=720
Now, what I do is extract substring as follows:
String fileNameWithParam = f.getVideoURL().substring(f.getVideoURL().lastIndexOf("/")+1);
String fileNameWithoutParam = fileNameWithParam.substring(0, fileNameWithParam.indexOf("?"));
fileName = fileNameWithoutParam;
Which works when the video URL has parameters appended and doesn't work when it does not have parameters appended to it.
Can someone please suggest a more general way to extract path to files from URL ? (without a specific file extension)
Upvotes: 0
Views: 71