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:net.ftb.util.FileUtils.java

public static void backupExtract(String zipLocation, String outputLocation) {
    Logger.logInfo("Extracting (Backup way)");
    byte[] buffer = new byte[1024];
    ZipInputStream zis = null;//  w w  w .j  a  v  a  2 s  . co m
    ZipEntry ze;
    try {
        File folder = new File(outputLocation);
        if (!folder.exists()) {
            folder.mkdir();
        }
        zis = new ZipInputStream(new FileInputStream(zipLocation));
        ze = zis.getNextEntry();
        while (ze != null) {
            File newFile = new File(outputLocation, ze.getName());
            newFile.getParentFile().mkdirs();
            if (!ze.isDirectory()) {
                FileOutputStream fos = new FileOutputStream(newFile);
                int len;
                while ((len = zis.read(buffer)) > 0) {
                    fos.write(buffer, 0, len);
                }
                fos.flush();
                fos.close();
            }
            ze = zis.getNextEntry();
        }
    } catch (IOException ex) {
        Logger.logError("Error while extracting zip", ex);
    } finally {
        try {
            zis.closeEntry();
            zis.close();
        } catch (IOException e) {
        }
    }
}

From source file:com.netflix.imfutility.inputparameters.InputParametersTest.java

@BeforeClass
public static void setupAll() throws IOException {
    // create both working directory and logs folder.
    FileUtils.deleteDirectory(TemplateParameterContextCreator.getWorkingDir());
    File workingDir = TemplateParameterContextCreator.getWorkingDir();
    if (!workingDir.mkdir()) {
        throw new RuntimeException("Could not create a working dir within tmp folder");
    }/*from  w  ww  . j ava2  s  .  c o m*/
    new File(workingDir, "config.xml");
}

From source file:com.appspresso.api.fs.FileSystemUtils.java

/**
 * InputStream  path?  ? .//from  w w w. j a va 2s  .c  o  m
 * 
 * @param inputStream ? InputStream
 * @param destFilePath  ??  path
 * @param overwrite  path? ? ??   ? 
 * @return ? {@literal true},   {@literal false}
 * @throws IOException ??   ?.
 */
public static boolean copy(InputStream inputStream, String destFilePath, boolean overwrite) throws IOException {
    File destFile = new File(destFilePath);
    File parent = destFile.getParentFile();
    if (!parent.exists() && !parent.mkdirs() && !parent.mkdir()) {
        return false;
    }

    if (destFile.exists()) {
        if (!overwrite) {
            return false;
        }
        if (!destFile.delete()) {
            return false;
        }
    }

    if (!destFile.createNewFile()) {
        return false;
    }

    FileOutputStream outputStream = null;
    try {
        outputStream = new FileOutputStream(destFile);
        BufferedOutputStream bOutputStream = new BufferedOutputStream(outputStream);

        byte[] buffer = new byte[BUFFER_SIZE];
        int length = -1;
        while ((length = inputStream.read(buffer, 0, BUFFER_SIZE)) != -1) {
            bOutputStream.write(buffer, 0, length);
        }
        bOutputStream.flush();
        return true;
    } finally {
        closeQuietly(inputStream);
        closeQuietly(outputStream);
    }
}

From source file:com.github.sakserv.minicluster.impl.KnoxLocalCluster.java

private static boolean ensureDirectoryExists(final File f) {
    return f.exists() || f.mkdir();
}

From source file:com.bhbsoft.videoconference.record.convert.util.FlvFileHelper.java

private static File getDir(File parent, String name) {
    File f = new File(parent, name);
    if (!f.exists()) {
        f.mkdir();
    }//from   ww  w .  ja v  a 2  s  .c  o m
    return f;
}

From source file:com.nokia.dempsy.mpcluster.zookeeper.ZookeeperTestServer.java

private static File genZookeeperDataDir() {
    File zkDir = null;
    try {/* www.j a  v a2s .  c om*/
        zkDir = File.createTempFile("zoo", "data");
        if (!zkDir.delete())
            throw new IOException("Can't rm zkDir " + zkDir.getCanonicalPath());
        if (!zkDir.mkdir())
            throw new IOException("Can't mkdir zkDir " + zkDir.getCanonicalPath());
    } catch (IOException e) {
        fail("Can't make zookeeper data dir");
    }
    return zkDir;
}

From source file:com.arcusys.liferay.vaadinplugin.util.WidgetsetUtil.java

private static File createTmpWorkDir(String dirName) throws IOException {
    File temp = File.createTempFile(dirName, null);

    if (!temp.delete()) {
        throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
    }//  w  w  w. j av  a 2  s  .co  m

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

    return temp;
}

From source file:mashapeautoloader.MashapeAutoloader.java

/**
 * @param libraryName//from   ww w.j a  va2  s  .c om
 *
 * Returns false if something wrong, otherwise true (API interface
 * already exists or just well downloaded)
 */
private static boolean downloadLib(String libraryName) {
    URL url;
    URLConnection urlConn;

    // check (or make) for apiStore directory
    File apiStoreDir = new File(apiStore);
    if (!apiStoreDir.isDirectory())
        apiStoreDir.mkdir();

    String javaFilePath = apiStore + libraryName + ".java";
    File javaFile = new File(javaFilePath);

    // check if the API interface exists
    if (javaFile.exists())
        return true;
    try {
        // download the API interface's archive
        url = new URL(MASHAPE_DOWNLOAD_ROOT + libraryName);
        urlConn = url.openConnection();

        HttpURLConnection httpConn = (HttpURLConnection) urlConn;
        httpConn.setInstanceFollowRedirects(false);

        urlConn.setDoInput(true);
        urlConn.setDoOutput(false);
        urlConn.setUseCaches(false);

        // extract the archive stream
        ZipInputStream zip = new ZipInputStream(urlConn.getInputStream());
        String expectedEntryName = libraryName + ".java";
        while (true) {
            ZipEntry nextEntry = zip.getNextEntry();
            if (nextEntry == null)
                return false;

            String name = nextEntry.getName();
            if (name.equals(expectedEntryName)) {
                // save .java locally
                FileOutputStream javaFileStream = new FileOutputStream(javaFilePath);
                byte[] buf = new byte[1024];
                int n;
                while ((n = zip.read(buf, 0, 1024)) > -1)
                    javaFileStream.write(buf, 0, n);

                // compile it into .class file
                JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
                int result = compiler.run(null, null, null, javaFilePath);
                System.out.println(result);
                return result == 0;
            }
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:edu.unc.lib.dl.util.FileUtils.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 w  w w .  jav a  2  s. c om
        // 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:eu.openanalytics.rsb.config.BootstrapConfigurationServletContextListener.java

private static File getOrCreateDefaultRsbHomeDirectory(final File rsbHomeParentDirectory) {
    final File rsbHomeDirectory = new File(rsbHomeParentDirectory, ".rsb");
    if (rsbHomeDirectory.isDirectory()) {
        return rsbHomeDirectory;
    }/*from   w  ww  .  java 2  s  .c om*/
    if (rsbHomeDirectory.mkdir()) {
        return rsbHomeDirectory;
    }
    LOGGER.info("Failed to create default RSB home directory under: " + rsbHomeDirectory);
    return null;
}