Android File Create overwriteFile(File file)

Here you can find the source of overwriteFile(File file)

Description

overwrite File

Declaration

public static File overwriteFile(File file) 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  .  jav a2s.  c  om*/

    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;
    }
}

Related

  1. getFile(File basedir, String path)
  2. getFile(String filepath)
  3. getOutputMediaFile(Context context)
  4. makeFile(File file)
  5. makeFile(String destinctionFile)
  6. verifyCanCreateFile(final String path, final long length)
  7. createTemporaryFile(String part, String ext)