Parse file name from URL before downloading the file

后端 未结 6 1649
眼角桃花
眼角桃花 2020-12-24 01:18

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 messag

6条回答
  •  -上瘾入骨i
    2020-12-24 02:09

    Get file name from FilenameUtils from apache commons-io

    URL url = URL(fileUrl)
    String fileName = FilenameUtils.getName(url.getPath())
    

    To this add commons-io dependency in build.gradle(app)

    implementation "commons-io:commons-io:2.6"
    

    It also extracts the file name from the complex URL like below

    http://www.example.com/some/path/to/a/file.xml?foo=bar#test

提交回复
热议问题