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:com.afforess.nsdump.Test.java

public static void testNationDump() throws IOException, SQLException {
    NationsDump dump = new NationsDump();
    dump.parse();/*from w  w  w.j a  va  2s  .co m*/

    Connection conn = dump.getDatabaseConnection();
    PreparedStatement statement = conn.prepareStatement("SELECT (name) FROM nations");
    ResultSet result = statement.executeQuery();
    int total = 0;
    while (result.next()) {
        total++;
    }
    result.close();

    System.out.println("Total nations: " + total);

    statement = conn.prepareStatement("SELECT * FROM nations WHERE name = 'sakhovelo'");
    result = statement.executeQuery();
    result.next();
    for (int i = 1; i <= 10; i++) {
        if (i == 4) {
            Clob clob = result.getClob(i);
            String motto = clob.getSubString(1, (int) clob.length());
            String mottoEscaped = StringEscapeUtils.unescapeHtml(motto);
            System.out.println("Raw: " + motto + " Escaped: " + mottoEscaped);
        } else {
            System.out.println(result.getString(i));
        }
    }

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

From source file:Main.java

public static void deleteTempFiles() {
    for (File f : myTempFiles)
        //noinspection ResultOfMethodCallIgnored
        f.delete();
}

From source file:Main.java

public static void deleteFile(String imageLocation) {
    if (imageLocation != null && imageLocation.trim().length() > 5) {
        File file = new File(imageLocation);
        if (file.exists()) {
            boolean fi = file.delete();
        }/*  ww w .  j a v  a 2 s.  c  o m*/
    }
}

From source file:Main.java

public static void saveSeriObj(Context context, String fileName, Object o) throws Exception {

    String path = context.getFilesDir() + "/";

    File dir = new File(path);
    dir.mkdirs();//from w ww.  ja  v  a2 s.c o m

    File f = new File(dir, fileName);

    if (f.exists()) {
        f.delete();
    }
    FileOutputStream os = new FileOutputStream(f);
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(os);
    objectOutputStream.writeObject(o);
    objectOutputStream.close();
    os.close();
}

From source file:Main.java

public static void bitmap2file(Bitmap bitmap, String path) {
    try {/*from   w w w .  j  a  va2 s.  c  om*/
        // create a file to write bitmap data
        File f = new File(path);
        if (f.exists()) {
            f.delete();
            f.createNewFile();
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bitmap.compress(CompressFormat.JPEG, 30 /* ignored for PNG */, bos);
        byte[] bitmapdata = bos.toByteArray();
        // write the bytes in file
        FileOutputStream fos = new FileOutputStream(f);
        fos.write(bitmapdata);
        fos.flush();
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.frederikam.fredboat.bootloader.Bootloader.java

private static void update() {
    //The main program has already prepared the shaded jar. We just need to replace the jars.
    File oldJar = new File("./" + jarName);
    oldJar.delete();
    File newJar = new File("./update/target/" + jarName);
    newJar.renameTo(oldJar);/*from  www. j  a  v  a 2  s  .  c o  m*/

    //Now clean up the workspace
    boolean deleted = new File("./update").delete();
    System.out.println("[BOOTLOADER] Updated. Update dir deleted: " + deleted);
}

From source file:Main.java

public static boolean deleteFile(String path) {
    File file = new File(path);
    if (file.exists()) {
        try {//from  w w  w. j av  a  2  s  . c om
            file.delete();
            return true;
        } catch (Exception e) {
            return false;
        }
    } else {
        return false;
    }
}

From source file:Main.java

/**
 * Deletes the given file on disk if it exists. If the file doesn't exist this will return
 * an error.//from  www . j a  v  a 2s. co  m
 *
 * @author Ian Copland
 *
 * @param in_filePath - The filename.
 *
 * @return Whether or not this was successful.
 */
public static boolean removeFile(String in_filePath) {
    if (doesFileExist(in_filePath) == false) {
        return false;
    }

    File file = new File(in_filePath);
    return file.delete();
}

From source file:Main.java

private static void deleteDir(File dir) {
    File[] files = dir.listFiles();
    if (files != null & files.length > 0) {
        for (File file : files) {
            if (file.isFile()) {
                file.delete();
            } else if (file.isDirectory()) {
                deleteDir(file);/* w w  w. j a v a 2 s  .co  m*/
            }
        }
    }
    dir.delete();
}

From source file:Main.java

public static void writeObjectToFile(Object oObject, File destDir, String filename) throws IOException {
    File dest = new File(destDir, filename);
    if (dest.exists())
        dest.delete();

    OutputStream outStream = null;
    try {//  w  w w  .  j a  v  a  2s .  c om
        outStream = new BufferedOutputStream(new FileOutputStream(dest));
        outStream.write((byte[]) oObject);
    } finally {
        if (outStream != null) {
            outStream.close();
        }
    }
}