Android Directory Create directory(File base, String dir)

Here you can find the source of directory(File base, String dir)

Description

Returns the File for a named directory.

License

Apache License

Parameter

Parameter Description
base the parent directory of <b>dir</b>
dir the name of the directory to find or create

Return

the directory found or created

Declaration

public static File directory(File base, String dir) throws IOException 

Method Source Code

/*/*from   w  w  w  .  j a v a 2  s  .  c  o m*/
    Copyright 1996-2008 Ariba, Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    $Id: //ariba/platform/util/core/ariba/util/core/FileUtil.java#24 $
 */

import ariba.util.log.Log;
import java.io.File;
import java.io.IOException;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.util.Random;
import java.util.List;

public class Main{
    /**
        Returns the File for a named directory. If there is no
        directory <B>dir</B> relative to the File <B>base</B>, it and
        all needed parent directories will be created.

        @param base the parent directory of <b>dir</b>
        @param dir the name of the directory to find or create

        @return the directory found or created

        @exception IOException if there was an error finding or
        creating the directory
        @aribaapi documented
     */
    public static File directory(File base, String dir) throws IOException {
        return directory(base.getPath(), dir);
    }
    /**
        Returns the File for a named directory. If there is no
        directory <B>dir</B> relative to the directory <B>base</B>, it
        and all needed parent directories will be created.

        @param base the parent directory of <b>dir</b>
        @param dir the name of the directory to find or create

        @return the directory found or created

        @exception IOException if there was an error finding or
        creating the directory
        @aribaapi documented
     */
    public static File directory(String base, String dir)
            throws IOException {
        return directory(new File(new File(base), dir));
    }
    /**
        Returns the File for a named directory. If there is no
        directory it and all needed parent directories will be
        created.

        @param dir the name of the directory to find or create

        @return the directory found or created

        @exception IOException if there was an error finding or
        creating the directory
        @aribaapi documented
     */
    public static File directory(String dir) throws IOException {
        return directory(new File(dir));
    }
    /**
        Returns the File for a directory. If there is no directory it
        and all needed parent directories will be created.

        @param dir the directory to find or create

        @return the directory found or created

        @exception IOException if there was an error finding or
        creating the directory
        @aribaapi documented
     */
    public static File directory(File dir) throws IOException {
        if (!dir.exists()) {
            if (!dir.mkdirs()) {
                throw new IOException(Fmt.S("can't create directory %s",
                        dir));
            }
        }

        if (!dir.isDirectory()) {
            throw new IOException(Fmt.S("%s is not a directory", dir));
        }

        return dir;
    }
}

Related

  1. createIfDoesntExist(File dir, boolean mustBeReadable, boolean mustBeWritable)
  2. createMissingParentDirectories(File file)
  3. createNewDirectory(String directorPath)
  4. createOrGetDir(String path, boolean mustBeReadable, boolean mustBeWritable)
  5. dirWritable(String dir)
  6. directory(File dir)
  7. directory(String base, String dir)
  8. directory(String dir)
  9. ensureDirectoryExist(File dir)