Android Directory Create createDirStructureForFile(File file)

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

Description

create Dir Structure For File

Declaration

@SuppressWarnings("unused")
    public static void createDirStructureForFile(File file) 

Method Source Code

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

public class Main {
    @SuppressWarnings("unused")
    public static void createDirStructureForFile(File file) {
        if (!file.exists()) {
            String[] dirs = file.getAbsolutePath().split(File.separator);
            String newFile = "";

            for (int index = 0; index < dirs.length - 1; index++)
                newFile += "/" + dirs[index];

            File currFile = new File(newFile);

            if (!currFile.exists())
                if (!currFile.mkdirs())
                    throw new RuntimeException(
                            "Could not create directory: "
                                    + currFile.getAbsolutePath());
        }/*from   w  w w .j a  v a  2 s .  c o m*/
    }
}

Related

  1. createDir(String directory)
  2. createDir(String path)
  3. createDir(final File path)
  4. createDirIfNotExists(File d)
  5. createDirIfNotExists(String d)
  6. createDirs(String dir, boolean ignoreIfExitst)
  7. createDirsForFile(File file)
  8. createIfDoesntExist(File dir, boolean mustBeReadable, boolean mustBeWritable)
  9. createMissingParentDirectories(File file)