Example usage for java.io File delete

List of usage examples for java.io File delete

Introduction

In this page you can find the example usage for java.io File delete.

Prototype

public boolean delete() 

Source Link

Document

Deletes the file or directory denoted by this abstract pathname.

Usage

From source file:Main.java

public static void deleteFromInternalStorage(Context context, final String contains) throws IOException {
    File file = context.getFilesDir();
    FilenameFilter filter = new FilenameFilter() {
        @Override/*ww  w.  j ava2 s.c  o  m*/
        public boolean accept(File dir, String filename) {
            return filename.contains(contains);
        }
    };
    File[] files = file.listFiles(filter);
    if (files != null) {
        for (File f : files) {
            //noinspection ResultOfMethodCallIgnored
            if (!f.delete()) {
                throw new IOException("Error while deleting files");
            }
        }
    }
}

From source file:Main.java

public static void saveBitmap(Bitmap bm, String picName) {
    try {//from   w  ww .j  a va2  s. c  o  m
        if (!isFileExist("")) {
            File tempf = createSDDir("");
        }
        File f = new File(SDPATH, picName + ".JPEG");
        if (f.exists()) {
            f.delete();
        }
        FileOutputStream out = new FileOutputStream(f);
        bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.alibaba.zonda.logger.server.util.FileUtil.java

public static boolean rename(File f1, File f2) {
    ensurePathExists(f2.getParent());// ww  w.  j a v a 2  s . co  m
    if (f2.exists())
        f2.delete();
    return f1.renameTo(f2);
}

From source file:de.geeksfactory.opacclient.webservice.LibraryConfigUpdateService.java

public static void clearConfigurationUpdates(Context context) {
    File filesDir = new File(context.getFilesDir(), LIBRARIES_DIR);
    filesDir.mkdirs();/* w  w w . j  a  v  a  2 s  . c  om*/
    File[] files = filesDir.listFiles();
    for (File file : files) {
        file.delete();
    }

    PreferenceDataSource prefs = new PreferenceDataSource(context);
    prefs.clearLastLibraryConfigUpdate();
}

From source file:Main.java

public static void rm(File f) {
    if (f.isDirectory()) {
        for (File ff : f.listFiles()) {
            rm(ff);//from   w  ww  .  j a va2  s .c o m
        }
        f.delete();
    } else if (f.isFile()) {
        f.delete();
    }
}

From source file:Main.java

public static void delete(File file) {
    if (!file.exists()) {
        return;/*from   ww  w .jav a  2 s.c  o  m*/
    }
    if (file.isFile()) {
        file.delete();
        return;
    }
    if (file.isDirectory()) {
        File[] childFiles = file.listFiles();
        if (childFiles == null || childFiles.length == 0) {
            file.delete();
            return;
        }

        for (int i = 0; i < childFiles.length; i++) {
            delete(childFiles[i]);
        }
        file.delete();
    }
}

From source file:Main.java

public static boolean saveBitmapToSDCard(Bitmap bitmap, String filePath, String fileName) {
    boolean flag = false;
    if (null != bitmap) {
        try {//from  w  w  w. j  a v  a  2 s .c o m
            fileName = fileName + ".jpg";
            File file = new File(filePath);
            if (!file.exists()) {
                file.mkdirs();
            }
            File f = new File(filePath + fileName);
            if (f.exists()) {
                f.delete();
            }
            BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(f));
            bitmap.compress(CompressFormat.JPEG, 100, outputStream);
            outputStream.flush();
            outputStream.close();
            flag = true;
        } catch (FileNotFoundException e) {
            flag = false;
        } catch (IOException e) {
            flag = false;
        }
    }
    return flag;

}

From source file:Main.java

public static void saveBoardToExternal(Context context, String fileName, JSONObject jsonObject) {
    File file = new File(getDirectoryBoards(), fileName);
    if (file.exists()) {
        file.delete();
    }//  www  .  j  ava 2s  .  c  o  m

    try {
        file.createNewFile();
        BufferedWriter buf = new BufferedWriter(new FileWriter(file, true));
        buf.append(jsonObject.toString());
        buf.close();
        addTomMediaScanner(context, file);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void deleteDir(File f) {
    if (f.exists() && f.isDirectory()) {
        for (File file : f.listFiles()) {
            if (file.isDirectory())
                deleteDir(file);/* w w w.  ja  v a 2  s  .  c om*/
            file.delete();
        }
        f.delete();
    }
}

From source file:Main.java

public static boolean saveFile(Bitmap bm, String path) {
    if (bm == null || path == null)
        return false;
    File myCaptureFile = new File(path);
    if (myCaptureFile.exists()) {
        myCaptureFile.delete();
    }//from   w  ww  .  j  av  a  2s  . c  om
    try {
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
        bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);
        bos.flush();
        bos.close();
        return true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}