0

因此,我试图从 URL 中提取 mp4 文件的路径。问题是它们在?. 例如:www.example.com/video.mp4?w=1280&h=720
现在,我要做的是提取子字符串,如下所示:

String fileNameWithParam = f.getVideoURL().substring(f.getVideoURL().lastIndexOf("/")+1);
String fileNameWithoutParam = fileNameWithParam.substring(0, fileNameWithParam.indexOf("?"));
fileName = fileNameWithoutParam;  

当视频 URL附加参数时有效,当它没有附加参数时无效。

有人可以建议一种更通用的方法来从 URL 中提取文件的路径吗?(没有特定的文件扩展名)

4

1 回答 1

1

尝试:

final String path = new URL(f.getVideoURL()).getPath();
于 2013-08-06T21:16:25.693 回答