Get fileName from uri on KitKat Document

若如初见. 提交于 2020-01-05 05:00:28

问题


I want to get fileName from a uri... I can get a fullpath from Other apps like gallery or other third party file managers, but I can't get fileName from KitKat Document, I don't need a fullPath just the fileName with an inputStream is good for me...

Thanks

Edit: I found a piece of code that solves the issue almost, but it can't get filePath of none known types like *.exe *.vcf , ...

Here's the source


回答1:


If you have the absolute path of file then simpley create the object of file and use getName method

File f = new File(<Full Path of your file>);

This will return file name with extension.

ANd if you do not want extension then use CommonsI/O libarary

And from that library you can use

String fileNameWithOutExt = FilenameUtils.removeExtension(fileNameWithExt);


来源:https://stackoverflow.com/questions/22068393/get-filename-from-uri-on-kitkat-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!