Get fileName from uri on KitKat Document

2019-08-10 21:47发布

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

标签: android uri
1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-10 22:21

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);
查看更多
登录 后发表回答