Android Utililty Methods File Create

List of utility methods to do File Create

Description

The list of methods to do File Create are organized into topic(s).

Method

voidensureWorldReadable(File f)
ensure World Readable
File parent = f.getParentFile();
if (parent != null && !parent.exists()) {
    ensureWorldReadable(parent);
    parent.mkdir();
    parent.setReadable(true, false);
    parent.setExecutable(true, false);
voidensureWorldWriteable(File f)
ensure World Writeable
File parent = f.getParentFile();
if (parent != null && !parent.exists()) {
    ensureWorldWriteable(parent);
    parent.mkdir();
    parent.setWritable(true, false);
    parent.setExecutable(true, false);
voidensureWriteable(File f)
Ensures that the directories for the file exist
File parent = f.getParentFile();
if (parent != null) {
    parent.mkdirs();
FilegetFile(File basedir, String path)
get File
File file = new File(path);
if (file.isAbsolute()) {
    return file;
return new File(basedir, path);
FilegetFile(String filepath)
get File
File f = new File(filepath);
if (!f.exists()) {
    f = new File("war", filepath);
return f;
FilegetOutputMediaFile(Context context)
get Output Media File
File mediaStorageDir = Environment
        .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
if (!mediaStorageDir.exists()) {
    if (!mediaStorageDir.mkdirs()) {
        return null;
String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm")
...
booleanmakeFile(File file)
make File
boolean result = false;
makeParent(file);
if (!file.exists()) {
    result = file.createNewFile();
return result;
voidmakeFile(String destinctionFile)
make File
File f = new File(destinctionFile);
File pf = f.getParentFile();
if (f.exists())
    return;
if (!pf.exists()) {
    pf.mkdirs();
try {
...
FileoverwriteFile(File file)
overwrite File
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;
booleanverifyCanCreateFile(final String path, final long length)
Checks if a file with a specified size can be created on a specified path.
final File file = new File(path);
if (!file.exists()) {
    final RandomAccessFile access;
    try {
        access = new RandomAccessFile(file, "rws");
    } catch (FileNotFoundException e) {
        return false;
    try {
        access.setLength(length);
        access.close();
    } catch (IOException e) {
        return false;
    return file.delete();
return false;