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 boolean removeTemporaryPhotoFile(File file) {
    boolean success = false;
    try {//from ww  w  .  j a va2s  . c  o m
        success = file.delete();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return success;
}

From source file:Main.java

public static void deleteCache(Context context, String key) {
    File cache = context.getFileStreamPath(key);
    if (cache.exists()) {
        cache.delete();
    }/*  w w  w .j a  v a 2 s. com*/
}

From source file:Main.java

public static boolean deleteFileIfExists(final String fileName) {
    if (fileName == null) {
        return false;
    }//from   w w w.j a  va  2s . com
    File file = new File(fileName);
    if (file.exists()) {
        return file.delete();
    }
    return false;
}

From source file:Main.java

private static void cleanDir(File dir, long bytes) {
    long bytesDeleted = 0;
    File[] files = dir.listFiles();

    for (File file : files) {
        bytesDeleted += file.length();//from   w w w . ja va 2  s. c  om
        file.delete();

        if (bytesDeleted >= bytes) {
            break;
        }
    }
}

From source file:Main.java

public static boolean deleteFile(String filePath) {
    if (TextUtils.isEmpty(filePath)) {
        return false;
    }//w  w  w .j  av  a  2  s.  c om
    File file = new File(filePath);
    if (file.exists()) {
        return file.delete();
    }
    return false;
}

From source file:com.afforess.nsdump.Test.java

public static void testRegionDump() throws IOException, SQLException {
    RegionsDump dump = new RegionsDump();
    dump.parse();//from   w ww. j av  a2  s. com

    Connection conn = dump.getDatabaseConnection();
    PreparedStatement statement = conn.prepareStatement("SELECT (numnations) FROM regions");
    ResultSet result = statement.executeQuery();
    int total = 0, regions = 0;
    while (result.next()) {
        total += result.getInt(1);
        regions++;
    }
    System.out.println("Total nations: " + total);
    System.out.println("Total regions: " + regions);
    result.close();
    conn.close();

    File db = new File("./ns-db.h2.db");
    db.delete();
}

From source file:Main.java

private static void createWorkingDir() throws IOException {
    if (workingDir == null) {
        if (workingDir == null) {
            workingDir = new File(".");
            workingDir = new File(workingDir, "target");
            workingDir = new File(workingDir, "apacheds_working").getCanonicalFile();
            if (!workingDir.exists()) {
                workingDir.mkdirs();//from w w  w .j a v  a 2 s.co m
            }
        }
    }
    for (File current : workingDir.listFiles()) {
        current.delete();
    }
}

From source file:Main.java

/**
 * Removes entities file.//from ww  w . j  a v  a 2s  .  c  o  m
 * @param context
 * @param fileName
 * @throws Exception 
 */
public static void removeAllEntities(Context context, String fileName) throws Exception {
    File file = new File(context.getFilesDir(), fileName);
    boolean deleted = file.delete();
    if (!deleted) {
        throw new Exception("Failed to remove file=" + fileName);
    }
}

From source file:Main.java

public static void saveBitmapToSDCard(Bitmap bitmap, String path) {
    File file = new File(path);
    if (file.exists()) {
        file.delete();
    }/* w  w w . j a va  2  s.  com*/
    FileOutputStream outputStream = null;
    try {
        outputStream = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
        outputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("----------save success-------------------");
}

From source file:Main.java

public static void saveBitmap(Bitmap bitmap, Bitmap.CompressFormat format, File target) {
    if (target.exists()) {
        target.delete();
    }//w  ww  .  j  ava2 s. c  om
    try {
        FileOutputStream out = new FileOutputStream(target);
        bitmap.compress(format, 100, out);
        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}