Example usage for java.io File mkdir

List of usage examples for java.io File mkdir

Introduction

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

Prototype

public boolean mkdir() 

Source Link

Document

Creates the directory named by this abstract pathname.

Usage

From source file:Main.java

public static boolean copyAssetsToInternalStorage(File assetFile, File storageFile, AssetManager assetManager) {
    try {// w w w .  j  ava 2  s. c om
        String[] assets = assetManager.list(assetFile.getPath());
        if (assets.length == 0) {
            //                return copyFile(assetManager.openFd(assetFile.getPath()).getFileDescriptor(), storageFile); //Fail!!!
            return copyFile(assetFile, storageFile, assetManager);
        } else {
            storageFile.mkdir();
            for (String file : assets) {
                copyAssetsToInternalStorage(new File(assetFile, file), new File(storageFile, file),
                        assetManager);
            }
        }
        return true;
    } catch (IOException ex) {
        return false;
    }
}

From source file:com.testmax.util.FileUtility.java

public static void copyFolder(File src, File dest) throws IOException {

    if (src.isDirectory()) {

        //if directory not exists, create it
        if (!dest.exists()) {
            dest.mkdir();
            System.out.println("Directory copied from " + src + "  to " + dest);
        }// w  ww  . j  a  v a 2 s . com

        //list all the directory contents
        String files[] = src.list();

        for (String file : files) {
            //construct the src and dest file structure
            File srcFile = new File(src, file);
            File destFile = new File(dest, file);
            //recursive copy
            copyFolder(srcFile, destFile);
        }

    } else {
        //if file, then copy it
        //Use bytes stream to support all file types
        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dest);

        byte[] buffer = new byte[1024];

        int length;
        //copy the file content in bytes 
        while ((length = in.read(buffer)) > 0) {
            out.write(buffer, 0, length);
        }

        in.close();
        out.close();
        System.out.println("File copied from " + src + " to " + dest);
    }
}

From source file:com.linkedin.restli.tools.idlgen.TestRestLiResourceModelExporter.java

public static File createTmpDir() throws IOException {
    File temp = File.createTempFile("temp", Long.toString(System.nanoTime()));
    if (!temp.delete()) {
        throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
    }//from   www .  j  a v  a 2 s .c om

    temp = new File(temp.getAbsolutePath() + ".d");

    if (!temp.mkdir()) {
        throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
    }

    return temp;
}

From source file:eu.sisob.uma.footils.File.FileFootils.java

public static void copyFolder(File src, File dest) throws IOException {

    if (src.isDirectory()) {

        //if directory not exists, create it
        if (!dest.exists()) {
            dest.mkdir();
        }/*from   ww w . j  av a  2 s.c  o  m*/

        //list all the directory contents
        String files[] = src.list();

        for (String file : files) {
            //construct the src and dest file structure
            File srcFile = new File(src, file);
            File destFile = new File(dest, file);
            //recursive copy
            copyFolder(srcFile, destFile);
        }

    } else {
        //if file, then copy it
        //Use bytes stream to support all file types
        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dest);

        byte[] buffer = new byte[1024];

        int length;
        //copy the file content in bytes 
        while ((length = in.read(buffer)) > 0) {
            out.write(buffer, 0, length);
        }

        in.close();
        out.close();
    }
}

From source file:com.sk89q.craftbook.mech.area.CopyManager.java

/**
 * Renames a namespace./* w  w  w  .  j  ava  2 s . co m*/
 * 
 * @param originalName The old name.
 * @param newName The new name. (Post rename)
 */
public static void renameNamespace(File dataFolder, String originalName, String newName) {

    File oldDir = new File(dataFolder, "areas/" + originalName);
    File newDir = new File(dataFolder, "areas/" + newName);
    if (oldDir.isDirectory()) {
        oldDir.renameTo(newDir);
    } else {
        oldDir.mkdir();
        oldDir.renameTo(newDir);
    }
}

From source file:mujava.cli.genmutes.java

static void setMutationSystemPathFor(String file_name) {
    try {//w  w w .  j a va  2 s  .  c  o  m
        String temp;
        temp = file_name.substring(0, file_name.length() - ".java".length());
        temp = temp.replace('/', '.');
        temp = temp.replace('\\', '.');
        int separator_index = temp.lastIndexOf(".");

        if (separator_index >= 0) {
            MutationSystem.CLASS_NAME = temp.substring(separator_index + 1, temp.length());
        } else {
            MutationSystem.CLASS_NAME = temp;
        }

        String mutant_dir_path = MutationSystem.MUTANT_HOME + "/" + temp;
        File mutant_path = new File(mutant_dir_path);
        mutant_path.mkdir();

        String class_mutant_dir_path = mutant_dir_path + "/" + MutationSystem.CM_DIR_NAME;
        File class_mutant_path = new File(class_mutant_dir_path);
        class_mutant_path.mkdir();

        String traditional_mutant_dir_path = mutant_dir_path + "/" + MutationSystem.TM_DIR_NAME;
        File traditional_mutant_path = new File(traditional_mutant_dir_path);
        traditional_mutant_path.mkdir();

        String original_dir_path = mutant_dir_path + "/" + MutationSystem.ORIGINAL_DIR_NAME;
        File original_path = new File(original_dir_path);
        original_path.mkdir();

        MutationSystem.CLASS_MUTANT_PATH = class_mutant_dir_path;
        MutationSystem.TRADITIONAL_MUTANT_PATH = traditional_mutant_dir_path;
        MutationSystem.ORIGINAL_PATH = original_dir_path;
        MutationSystem.DIR_NAME = temp;
    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:eu.scape_project.tool.toolwrapper.core.utils.Utils.java

/**
 * Method useful to copy a particular resource (file under
 * src/main/resources) to a temporary directory
 * /*from w  ww.j  a  v a2 s .c o m*/
 * @param tempDir
 *            directory where the resource is being put on
 * @param resourcePath
 *            the path to the resource (beneath src/main/resources)
 * @param resourceName
 *            the name of the resource being copied
 * @param newName
 *            new name to be given to the resouce being copied
 * @param createTempDir
 *            flag on either the temporary directory needs to be created
 * @param invokingClass
 *            class to which the resource is related to
 * @return true if the resource was successfully copied, false otherwise
 * */
public static boolean copyResourceToTemporaryDirectory(File tempDir, String resourcePath, String resourceName,
        String newName, boolean createTempDir, Class<?> invokingClass) {
    boolean success = false;
    FileOutputStream fileOutputStream = null;
    try {
        if (createTempDir && !tempDir.mkdir()) {
            log.error("Error creating directory \"" + tempDir + "\"...");
        }
        File f = new File(tempDir, newName != null ? newName : resourceName);
        fileOutputStream = new FileOutputStream(f);
        IOUtils.copy(invokingClass.getResourceAsStream(resourcePath + resourceName), fileOutputStream);
        success = true;
    } catch (IOException e) {
        log.error(e);
    } finally {
        if (fileOutputStream != null) {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                log.error(e);
            }
        }
    }
    return success;
}

From source file:net.cloudkit.enterprises.infrastructure.utilities.FreemarkerHelper.java

public static String process(String templateName, Map<String, ?> model, String target) {
    String result = null;/*from  w  w w.ja v a  2s.  com*/

    FileOutputStream fileOutputStream = null;
    OutputStreamWriter outputStreamWriter = null;
    Writer writer = null;
    File file = new File(target);
    if (!file.exists()) {
        if (file.isDirectory()) {
            file.mkdirs();
        } else {
            file.mkdir();
        }
    }
    try {
        fileOutputStream = new FileOutputStream(file);
        outputStreamWriter = new OutputStreamWriter(fileOutputStream, "UTF-8");
        // new OutputStreamWriter(new FileOutputStream(file), "UTF-8")
        writer = new BufferedWriter(outputStreamWriter);
        result = process(templateName, model, writer);
        writer.flush();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {

        IOUtils.closeQuietly(writer);
        IOUtils.closeQuietly(outputStreamWriter);
        IOUtils.closeQuietly(fileOutputStream);

        // try {
        //     writer.close();
        // } catch (IOException e) {
        //     e.printStackTrace();
        // }
    }
    return result;
}

From source file:com.tasktop.c2c.server.internal.profile.service.template.GitServiceCloner.java

public static File createTempDirectory() throws IOException {
    File temp = File.createTempFile("temp", Long.toString(System.nanoTime()));

    if (!temp.delete()) {
        throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
    }/*from   w  w  w  . j a  va2 s.c  o m*/

    if (!temp.mkdir()) {
        throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
    }

    return temp;
}

From source file:com.fluidops.iwb.deepzoom.DZConvert.java

/**
 * Creates a directory//w  w  w . j  a  va 2  s.c  o m
 * @param parent the parent directory for the new directory
 * @param name the new directory name
 */
private static File createDir(File parent, String name) throws IOException {
    assert (parent.isDirectory());
    File result = new File(parent + File.separator + name);
    if (!result.mkdir())
        throw new IOException("Unable to create directory: " + result);
    return result;
}