如何刪除sdcard中的文件?
public void onClick(DialogInterface dialog, int which) {
File dir = new File (Environment.getExternalStorageDirectory() + "/MyApp/MyFolder");
if (dir.isDirectory())
{
File file = new File(card.imagePath);
file.delete();
}
public static void delDir(File file) {
boolean bool = false;
if (file.isFile()) {
bool = file.delete();
System.out.println("Delete file[" + file.getAbsolutePath() + "," + bool + "]");
} else {
File[] children = file.listFiles();
if (children != null) {
for (File child : children) {
if (child.isFile()) {
bool = child.delete();
System.out.println("Delete file[" + child.getAbsolutePath() + "," + bool + "]");
} else {
delDir(child);
}
}
}
bool = file.delete();
System.out.println("Delete folder[" + file.getAbsolutePath() + "," + bool + "]");
}
}
public static void delDir(String path) {
File file = new File(path);
delDir(file);
}