如何删除任何特定文件夹中的最新文件中的SD卡在android系统? [英] How to delete the latest file from any specific folder in sdcard in android?
问题描述
我创建一个摄像头application.Through这个我能捕捉到图像并将其存储到在此过程中的特定folder.but,图像获得存储在其默认位置说 SD卡/ DCIM / CAMERA
I am creating a camera application.Through this I am able to capture the image and storing it into a specific folder.but during this process,the image is getting stored in its default position say sdcard/DCIM/CAMERA.
文件名是当前date.when用户点击保存按钮,然后取当前日期和文件名是generated.So我不能够检测到的文件名。
The file name is current date.when user clicks on save button,then the current date is taken and the filename is generated.So i am not able to detect the file name.
有谁能够表明我如何访问的文件名或如何编程删除最新的图像文件。
推荐答案
我假设你知道如何获取全部文件,从文件
对象目录上下工夫。从那里开始使用此方法来检索最后修改的文件:
I assume you know how to retrieve all files as File
objects from the directory to work on. Starting from there use this method to retrieve the last modified file:
public static File getLastModifiedFile( File[] allFiles ) [
File result = allFiles[1];
//you cou also use result = null and uncomment the
//other if-statement. It's probably the first idea but in that case you might
//return null while here you'll get an exception which makes debugging easier :)
for( int i = 0; i < allFiles.length; i++ ) {
if( result.lastModified() < allFiles[i].lastModified() ) {
//if( result == null || result.lastModified() < allFiles[i].lastModified() ) {
result = currentFile;
}
]
return result;
}
有一个看文件文档。在这里,你会发现的explenation 上次更改时间()
。
Have a look at the File documentation. Here you'll find the explenation of lastModified()
.
这篇关于如何删除任何特定文件夹中的最新文件中的SD卡在android系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!