Surround file deletion with a try catch block

This commit is contained in:
Rashiq 2015-06-18 11:21:39 +02:00
parent 95a606ed8d
commit ef25f8ea16

View File

@ -2,11 +2,11 @@ package org.kiwix.kiwixmobile;
import org.kiwix.kiwixmobile.settings.Constants;
import java.io.File;
import android.content.Context;
import android.os.Environment;
import java.io.File;
public class FileUtils {
public static File getFileCacheDir(Context context) {
@ -21,11 +21,14 @@ public class FileUtils {
}
public static void deleteCachedFiles(Context context) {
for (File file : getFileCacheDir(context).listFiles()) {
file.delete();
public static synchronized void deleteCachedFiles(Context context) {
try {
for (File file : getFileCacheDir(context).listFiles()) {
file.delete();
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
@ -61,7 +64,7 @@ public class FileUtils {
* @return true if it does exist, false otherwise
*/
static public boolean doesFileExist(String fileName, long fileSize,
boolean deleteFileOnMismatch) {
boolean deleteFileOnMismatch) {
// the file may have been delivered by Market --- let's make sure
// it's the size we expect
File fileForNewFile = new File(fileName);