我目前正在处理内部存储。
我有些问题,
data/data/com.example.app/sample.mp4,但我只想要像sample.mp4这样的文件名。这是我的代码
`
ArrayList<File> fileList = new ArrayList<File>();
File mydir = this.getDir("Myfolder", Context.MODE_PRIVATE);
File listFile[] = mydir.listFiles();
if (listFile != null && listFile.length > 0) {
for (File aListFile : listFile) {
if (aListFile.isDirectory()) {
fileList.add(aListFile);
} else {
if (aListFile.isFile());
{
fileList.add(aListFile);
}
}
}`发布于 2017-03-24 11:29:21
从文件对象获取文件名
if (aListFile.isFile());
{
string fileName = aListFile.getName();
}发布于 2017-03-24 11:15:42
试试这个,
YourFilePath.substring(YourFilePath.lastIndexOf("/")+1)例如,
String filePath = "data/data/com.example.app/sample.mp4" String fileName = filePath.subString(filePath.lastIndexOf("/")+1);
最后你得到了你的fileName = sample.mp4
https://stackoverflow.com/questions/42998014
复制相似问题