create New File for append - Android File Input Output

Android examples for File Input Output:File Exist

Description

create New File for append

Demo Code


//package com.book2s;

import java.io.File;

public class Main {

    public static File createNewFile(String path, boolean append) {
        File newFile = new File(path);
        if (!append) {
            if (newFile.exists()) {
                newFile.delete();//from ww w .j  ava2  s .c o  m
            }
        }
        if (!newFile.exists()) {
            try {
                File parent = newFile.getParentFile();
                if (parent != null && !parent.exists()) {
                    parent.mkdirs();
                }
                newFile.createNewFile();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return newFile;
    }
}

Related Tutorials