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:com.frostwire.android.gui.util.FileUtils.java

/**
 * @param parentDir/*w ww . j a va 2 s  . co  m*/
 */
public static File createFolder(File parentDir, String folderName) {
    File f = new File(parentDir, folderName);
    if (!f.exists() || !f.isDirectory()) {
        f.mkdir();
    }
    return f;
}

From source file:com.worldline.easycukes.commons.helpers.FileHelper.java

/**
 * Extracts the content of a zip folder in a specified directory
 *
 * @param from a {@link String} representation of the URL containing the zip
 *             file to be unzipped/*from  www . ja va  2 s.  c  o m*/
 * @param to   the path on which the content should be extracted
 * @throws IOException if anything's going wrong while unzipping the content of the
 *                     provided zip folder
 */
public static void unzip(@NonNull String from, @NonNull String to, boolean isRemote) throws IOException {
    @Cleanup
    ZipInputStream zip = null;
    if (isRemote)
        zip = new ZipInputStream(new FileInputStream(from));
    else
        zip = new ZipInputStream(FileHelper.class.getResourceAsStream(from));
    log.debug("Extracting zip from: " + from + " to: " + to);
    // Extract without a container directory if exists
    ZipEntry entry = zip.getNextEntry();
    String rootDir = "/";
    if (entry != null)
        if (entry.isDirectory())
            rootDir = entry.getName();
        else {
            final String filePath = to + entry.getName();
            // if the entry is a file, extracts it
            try {
                extractFile(zip, filePath);
            } catch (final FileNotFoundException fnfe) {
                log.warn(fnfe.getMessage(), fnfe);
            }
        }
    zip.closeEntry();
    entry = zip.getNextEntry();
    // iterates over entries in the zip file
    while (entry != null) {
        String entryName = entry.getName();
        if (entryName.startsWith(rootDir))
            entryName = entryName.replaceFirst(rootDir, "");
        final String filePath = to + "/" + entryName;
        if (!entry.isDirectory())
            // if the entry is a file, extracts it
            try {
                extractFile(zip, filePath);
            } catch (final FileNotFoundException fnfe) {
                log.warn(fnfe.getMessage(), fnfe);
            }
        else {
            // if the entry is a directory, make the directory
            final File dir = new File(filePath);
            dir.mkdir();
        }
        zip.closeEntry();
        entry = zip.getNextEntry();
    }
    // delete the zip file if recovered from URL
    if (isRemote)
        new File(from).delete();
}

From source file:com.aionemu.packetsamurai.parser.valuereader.ClientStringReader.java

public static void load() {
    //PacketSamurai.getUserInterface().log("Loading Client strings... Please wait.");
    Util.drawTitle("Client Strings");
    File stringsFolder = new File("./data/client_strings");
    if (!stringsFolder.exists()) {
        stringsFolder.mkdir();
    }/*ww  w .  j  ava  2s.  com*/
    try {
        File[] files = stringsFolder.listFiles();
        File[] arrayOfFile1;
        int j = (arrayOfFile1 = files).length;
        for (int i = 0; i < j; i++) {
            File sFile = arrayOfFile1[i];
            File xml = new File(sFile.getPath());

            String stringFile = FileUtils.readFileToString(xml);
            String[] strings = StringUtils.substringsBetween(stringFile, "<string>", "</string>");
            if (strings != null) {
                String[] arrayOfString1;
                int m = (arrayOfString1 = strings).length;
                for (int k = 0; k < m; k++) {
                    String string = arrayOfString1[k];
                    int stringId = Integer.parseInt(StringUtils.substringBetween(string, "<id>", "</id>"));
                    String stringBody = StringUtils.substringBetween(string, "<body>", "</body>");
                    stringsById.put(Integer.valueOf(stringId), stringBody);
                }
            }
        }
        PacketSamurai.getUserInterface().log(
                "Strings [Client] - Loaded " + stringsById.size() + " strings from " + files.length + " Files");
    } catch (IOException e) {
        PacketSamurai.getUserInterface().log("ERROR: Failed to load client_strings.xsd: " + e.toString());
        e.printStackTrace();
    }
}

From source file:co.cask.cdap.filetailer.tailer.TailerLogUtils.java

public static void createTestDirIfNeed() throws ConfigurationLoadingException {
    PipeConfiguration flowConf = loadConfig();
    File dir = flowConf.getSourceConfiguration().getWorkDir();
    if (!dir.exists()) {
        dir.mkdir();
    }//from   w w  w. ja va2s  .  c o  m
}

From source file:mujava.cli.testnew.java

static void makeDir(File dir) {
    Util.DebugPrint("\nMake " + dir.getAbsolutePath() + " directory...");
    boolean newly_made = dir.mkdir();
    if (!newly_made) {
        Util.Error(dir.getAbsolutePath() + " directory exists already.");
    } else {/*from   w w  w.  j av  a2s .  c  o m*/
        Util.DebugPrint("Making " + dir.getAbsolutePath() + " directory " + " ...done.");
    }
}

From source file:net.itransformers.idiscover.v2.core.Main.java

public static String autolabel(String projectPath) {
    File networkPath = new File(projectPath, "network");

    if (!networkPath.exists()) {
        networkPath.mkdir();

        File labelDir = new File(networkPath, "version1");
        labelDir.mkdir();//from  w  ww  .  j  av a 2  s  .  c o  m
        return "network" + File.separator + "version1";
    }
    String[] fileList = new File(projectPath, "network").list();
    int max = 0;
    for (String fName : fileList) {
        if (fName.matches(VERSION_LABEL + "\\d+")) {
            int curr = Integer.parseInt(fName.substring(VERSION_LABEL.length()));
            if (max < curr)
                max = curr;
        }
    }
    return "network" + File.separator + VERSION_LABEL + (max + 1);
}

From source file:com.microsoft.azure.hdinsight.util.HDInsightJobViewUtils.java

private static void extractJobViewResource() {
    URL url = HDInsightJobViewUtils.class.getResource("/resources/" + HTML_ZIP_FILE_NAME);
    URL hdinsightJobViewJarUrl = HDInsightJobViewUtils.class
            .getResource("/resources/" + HDINSIGHT_JOB_VIEW_JAR_NAME);
    File indexRootFile = new File(PluginUtil.pluginFolder + File.separator + HTML_FOLDER_NAME);
    if (!indexRootFile.exists()) {
        indexRootFile.mkdir();
    }/*from  w  ww .ja  v a  2  s . c o m*/
    File toFile = new File(indexRootFile.getAbsolutePath(), HTML_ZIP_FILE_NAME);
    File hdinsightJobViewToFile = new File(indexRootFile.getAbsolutePath(), HDINSIGHT_JOB_VIEW_JAR_NAME);
    try {
        FileUtils.copyURLToFile(url, toFile);
        FileUtils.copyURLToFile(hdinsightJobViewJarUrl, hdinsightJobViewToFile);
        HDInsightJobViewUtils.unzip(toFile.getAbsolutePath(), toFile.getParent());
        DefaultLoader.getIdeHelper().setProperty(HDINSIGHT_JOBVIEW_EXTRACT_FLAG, "true");
    } catch (IOException e) {
        Activator.getDefault().log("Extract Job View Folder", e);
    }
}

From source file:Main.java

private static String getExternalStoragePathByContext(String path, Context context) {
    File dirPath = context.getExternalFilesDir(path);
    if (dirPath == null) {
        dirPath = new File(context.getExternalFilesDir(null).getAbsolutePath() + "/" + path + "/");
    }//from w ww.  ja v  a2  s. c o  m

    if (!dirPath.exists()) {
        dirPath.mkdir();
    }
    return dirPath.getAbsolutePath();
}

From source file:edu.american.student.stonewall.util.Deployer.java

private static void walkin(File dir, File deployDir) throws IOException {
    File listFile[] = dir.listFiles();
    if (listFile != null) {
        for (int i = 0; i < listFile.length; i++) {
            if (listFile[i].isDirectory()) {
                File f = new File(deployDir.getAbsolutePath() + File.separator + listFile[i].getName());
                f.mkdir();
                walkin(listFile[i], f);//from   w ww .j a v a2 s . co  m
            } else {
                System.out.println("found resource:" + listFile[i].getAbsolutePath());
                saveResource(listFile[i], deployDir);
            }
        }
    }
}

From source file:Main.java

public static File generateFile(String path) {
    File file = new File(folderName, ".nomedia");
    if (!file.exists()) {
        try {//  ww w  .j a  va2s  . c om
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
            file.mkdir();
        }
    }
    return new File(folderName(), generateFileName(path));
}