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:net.estinet.gFeatures.Feature.FusionPlay.GameUtil.WorldUtil.java

public static void copyWorld(File f) {
    Bukkit.getLogger().info("[FusionPlay] Loading world " + f.getName() + "...");
    File fz = new File("./world");
    fz.delete();
    try {/*w w  w.  j  a  va 2s  . c o  m*/
        FileUtils.copyDirectory(f, fz);
        Bukkit.getLogger().info("[FusionPlay] World loading completed.");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void deleteDir() {
    File dir = new File(SD_PATH);
    if (!dir.exists() || !dir.isDirectory())
        return;//from w  ww . j a  v  a2  s .  c  o m

    for (File file : dir.listFiles()) {
        if (file.isFile())
            file.delete();
        else if (file.isDirectory())
            deleteDir();
    }
    dir.delete();
}

From source file:Main.java

public static void saveObj(Object obj, String fileName) throws IOException {
    File f = new File(fileName + ".tmp");
    f.getParentFile().mkdirs();//from   w ww  .ja  v  a  2s .  com
    FileOutputStream fos = new FileOutputStream(f);
    ObjectOutputStream out = new ObjectOutputStream(fos);
    out.writeObject(obj);
    out.flush();
    out.close();
    fos.flush();
    fos.close();
    File file = new File(fileName);
    file.delete();
    f.renameTo(file);
}

From source file:Main.java

public static boolean deleteFile(File f) {
    if (f != null && f.exists() && !f.isDirectory()) {
        return f.delete();
    }//  w  w w.j a  v a2s  .c o  m
    return false;
}

From source file:Main.java

public static void delFile(String path) {
    if (TextUtils.isEmpty(path)) {
        return;//from   w w w  .ja v  a  2  s.co m
    }

    try {
        File file = new File(path);
        if (file.exists()) {
            file.delete();
        }
    } catch (Exception ignore) {

    }
}

From source file:Main.java

public static boolean deleteImageFile(String filepath) {

    File file = new File(filepath);
    if (file.exists()) {
        boolean deleted = file.delete();
    }//from  ww w  .j av a2s  . c  om
    return true;
}

From source file:Main.java

public static void writeNewFile(String filePath, String fileContents) {
    File f = new File(filePath);
    if (f.exists()) {
        f.delete();
    }//w  w w  .  j  a  v a2  s. c  o  m

    try {
        // Create file 
        FileWriter fstream = new FileWriter(f);
        BufferedWriter out = new BufferedWriter(fstream);
        out.write(fileContents);
        //Close the output stream
        out.close();
    } catch (Exception e) {
        Log.d(TAG, "Failed to create " + filePath + " File contents: " + fileContents);
    }
}

From source file:Main.java

public static void deleteFile(String path) {
    try {/*from  w w  w. j  a  v  a  2 s.com*/
        File file = new File(path);
        if (file.exists()) {
            file.delete();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void writeNewFile(String filePath, String fileContents) {
    File f = new File(filePath);
    if (f.exists()) {
        f.delete();
    }/*from ww  w .  j  a  v a2 s .c om*/

    try {
        // Create file
        FileWriter fstream = new FileWriter(f);
        BufferedWriter out = new BufferedWriter(fstream);
        out.write(fileContents);
        //Close the output stream
        out.close();
    } catch (Exception e) {
        Log.d(TAG, "Failed to create " + filePath + " File contents: " + fileContents);
    }
}

From source file:Main.java

public static void deleteDir() {
    File dir = new File(SDPATH);
    if (dir == null || !dir.exists() || !dir.isDirectory())
        return;/*w w w  . ja  va2s . co m*/

    for (File file : dir.listFiles()) {
        if (file.isFile())
            file.delete();
        else if (file.isDirectory())
            deleteDir();
    }
    dir.delete();
}