直接上代碼了..
[java]
private boolean deleteLastFromFloder(String path) {
boolean success = false;
try {
ArrayList<File> images = new ArrayList<File>();
getFiles(images, path);
File latestSavedImage = images.get(0);
if (latestSavedImage.exists()) {
for (int i = 1; i < images.size(); i++) {
File nextFile = images.get(i);
if (nextFile.lastModified() > latestSavedImage.lastModified()) {
latestSavedImage = nextFile;
}
}
Log.e("brady", "images = " + latestSavedImage.getAbsolutePath());
success = latestSavedImage.delete();
}
} catch (Exception e) {
e.printStackTrace();
}
return success;
}
private void getFiles(ArrayList<File> fileList, String path) {
File[] allFiles = new File(path).listFiles();
for (int i = 0; i < allFiles.length; i++) {
File file = allFiles[i];
if (file.isFile()) {
fileList.add(file);
} else if (!file.getAbsolutePath().contains(".thumnail")) {
getFiles(fileList, file.getAbsolutePath());
}
}
}