在下载文件之前,从URL解析文件名 [英] Parse file name from URL before downloading the file

查看:807
本文介绍了在下载文件之前,从URL解析文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从一个URL下载一个ePub文件。

I'm downloading an ePub file from a URL.

现在我想实现一个机制,如果用户尝试重新下载同一个文件,他应该收到警告/错误消息,并且该文件不应该再次下载。

Now I want to implement a mechanism by which if user tries to re-download the same file, he should get warning/error message and that file should not be downloaded again.

为了实现这一点,我需要检查文件的名称在我的图书馆中出现了用户正在尝试下载的文件名。

To implement this, I need to check the name of the file present in my library with the name of the file user is trying to download.

但是我只是有一个此下载链接,而不是文件名。

But I just have this download link, and not the file name.

如何在下载之前获取文件的名称将其与现有文件进行比较?

How to get the name of the file before download in order to compare it with the existing file?

推荐答案

应该这样做:

String fileName = url.substring(url.lastIndexOf('/') + 1);

(假设您的网址格式为: http://xxxxxxxxxxxxx/filename.ext

(Assuming your url is in the format: http://xxxxxxxxxxxxx/filename.ext)

或者您可以尝试

URLUtil.guessFileName(url, null, null)

有关详细信息,请参阅 here

Details about it are here

这篇关于在下载文件之前,从URL解析文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆