Android File Overwrite overwriteFile(File dir, String name)

Here you can find the source of overwriteFile(File dir, String name)

Description

overwrite File

Declaration

public static File overwriteFile(File dir, String name)
            throws IOException 

Method Source Code

//package com.java2s;
import java.io.File;
import java.io.IOException;

public class Main {
    public static File overwriteFile(File dir, String name)
            throws IOException {
        File file = new File(dir, name);
        return overwriteFile(file);
    }/*from w w w. j  a  v  a2  s  .  com*/

    public static File overwriteFile(File file) throws IOException {
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        if (file.exists()) {
            if (!file.delete()) {
                throw new IOException("Unable to delete output file");
            }
        }
        if (!file.createNewFile()) {
            throw new IOException("Unable to create output file");
        }
        return file;
    }
}