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

查看:207
本文介绍了下载文件前,从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.

要实现这一点,我需要用文件的用户名检查的文件present的名字在我的图书馆正在尝试下载。

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);

(假设你的URL的格式为:xxxxxxxxxxxxxxxxxx / filaneme.ext)

(Assuming your url is in the format: xxxxxxxxxxxxxxxxxx/filaneme.ext)

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

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