Example usage for java.io File mkdirs

List of usage examples for java.io File mkdirs

Introduction

In this page you can find the example usage for java.io File mkdirs.

Prototype

public boolean mkdirs() 

Source Link

Document

Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories.

Usage

From source file:Main.java

public static boolean createNewDirectory(File file) {
    if (file.exists() && file.isDirectory()) {
        return false;
    }//from  w w  w  . j  av  a 2  s  .com
    return file.mkdirs();
}

From source file:Utils.java

/**
 * Create a unique directory within a directory 'root'
 * //from   w ww .  j  a va2  s.  c o  m
 * @param rootDir
 * @param seed
 * @return unique directory
 * @throws IOException
 */
public static synchronized File createUniqueDirectory(File rootDir, String seed) throws IOException {
    int index = seed.lastIndexOf('.');
    if (index > 0) {
        seed = seed.substring(0, index);
    }
    File result = null;
    int count = 0;
    while (result == null) {
        String name = seed + "." + count + ".tmp";
        File file = new File(rootDir, name);
        if (!file.exists()) {
            file.mkdirs();
            result = file;
        }
        count++;
    }
    return result;
}

From source file:com.baidu.terminator.manager.common.file.FileUtils.java

public static void createFile(String fileLocation) {
    File file = new File(fileLocation);
    File parentFile = file.getParentFile();
    if (!parentFile.exists()) {
        parentFile.mkdirs();
    }// w w  w .  j  a  v a  2 s  . c  om
    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (IOException e) {
            LOGGER.error("create file :" + fileLocation + " fail!");
        }
    }
}

From source file:Main.java

public static Boolean mkDirs(String filePath) {
    //int startind=1;
    String dirPath = new File(filePath).getParentFile().getAbsolutePath() + File.separator;

    File dir = new File(dirPath.replace("/", File.separator));
    return dir.exists() || dir.mkdirs();
    //        while(true){
    //             if(startind>=dirPath.length()||startind==-1)
    //                return true;
    //            int slashInd=dirPath.indexOf(File.separator,startind);
    //            if(slashInd==-1)return true;
    //            String subPath=dirPath.substring(0,slashInd);
    //            File f=new File(subPath);
    //            if(!f.exists()&&!f.mkdir()){
    //                return false;
    //            }
    //            startind=subPath.length()+1;
    ////from w w w .  j av  a  2  s .com
    //        }

}

From source file:io.logspace.system.SystemTestUtils.java

public static void prepareDemoDirectory() {
    try {//from  www  .j a  v  a2  s. c  o m
        File directory = new File(System.getProperty("java.io.tmpdir"), "logspace-demo");
        directory.mkdirs();
        FileUtils.cleanDirectory(directory);
    } catch (IOException e) {
        // do nothing (cleanDirectory may fail on Windows systems because the directory could be in use by an old process)
    }
}

From source file:Main.java

/**
 * Prepares the destination directory by creating directories if needed 
 * @param destination The destination directory
 * @throws IOException//w ww. j a  v a  2 s .  c o  m
 */
public static void prepareDestination(File destination) throws IOException {
    File parent = destination.getParentFile();

    if (!parent.exists()) {
        if (!parent.mkdirs()) {
            throw new IOException("Unable to create destination directory: " + parent.getPath());
        }
    }
}

From source file:Main.java

public static File getPicturePath() {
    File path = new File(Environment.getExternalStorageDirectory(), PATH_IMG);
    if (!path.exists()) {
        path.mkdirs();
    }/*  w  ww  . java  2s .  c o m*/
    return path;
}

From source file:Main.java

/**
 * Get a usable cache directory (external if available, internal otherwise)
 *
 * @param context The {@link android.content.Context} to use
 * @param uniqueName A unique directory name to append to the cache
 *            directory/*  w w  w. j  a va2 s. c o  m*/
 * @return The cache directory
 */
public static File getCacheDir(final Context context, final String uniqueName) {
    File cachePath = context.getExternalCacheDir();
    if (cachePath == null || !cachePath.canWrite()) {
        cachePath = context.getCacheDir();
    }
    File cacheDir = new File(cachePath, uniqueName);
    if (!cacheDir.exists()) {
        cacheDir.mkdirs();
    }
    if (!cacheDir.canWrite()) {
        cacheDir.setWritable(true);
    }
    return cacheDir;
}

From source file:Main.java

/**
 * @param imgName//  w w  w.j a  v  a 2  s. c om
 * @return
 */
public static Bitmap getBitmapFromPath(String imgName) {
    String sExtendSdcardDir = "";
    String sAppRoot = "";

    String sdcardRoot = Environment.getExternalStorageDirectory() == null ? ""
            : Environment.getExternalStorageDirectory().getAbsolutePath();
    Log.d("Tiny", "sdcardRoot --" + sdcardRoot);

    if (sdcardRoot != null) {
        sExtendSdcardDir = sdcardRoot;
        sAppRoot = sExtendSdcardDir.concat("/TINY");
    }

    String sCache = sAppRoot.concat("/cache");

    File file = new File(sCache);
    if (!file.exists()) {
        file.mkdirs();
    }
    Log.d("Tiny", "file path --" + file.getAbsolutePath());

    File image = new File(file.getAbsolutePath(), imgName);
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(), bmOptions);
    return bitmap;
}

From source file:com.homeproject.tafulop.fxtest.FileHandling.java

/**
 * Creates a folder to store the resized images.
 * @param parentFolder The parent folder path in string representation, where the resized folder should be created as a child.
 * @return The folder where the resized files should be stored.
 *///from  w  w w  . j av a 2s  .com
private static File checkResizedFolder(String parentFolder) {

    File resizedFolder = new File(parentFolder + DIR_SEPARATOR + RESIZED_FOLDER_NAME);
    resizedFolder.mkdirs();
    return resizedFolder;
}