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.aurel.track.dbase.InitReportTemplateBL.java

public static void addReportTemplates() {
    URL urlSrc;/*from   w ww .ja  v a2  s .  co  m*/
    File srcDir = null;
    //first try to get the template dir through class.getResource(path)
    urlSrc = PluginUtils.class.getResource("/resources/reportTemplates");
    urlSrc = PluginUtils.createValidFileURL(urlSrc);
    if (urlSrc != null) {
        LOGGER.info("Retrieving report templates from " + urlSrc.toString());
        srcDir = new File(urlSrc.getPath());
        Long uuid = new Date().getTime();
        File tmpDir = new File(
                System.getProperty("java.io.tmpdir") + File.separator + "TrackTmp" + uuid.toString());
        if (!tmpDir.isDirectory()) {
            tmpDir.mkdir();
        }
        tmpDir.deleteOnExit();

        File[] files = srcDir.listFiles(new InitReportTemplateBL.Filter());
        if (files == null || files.length == 0) {
            LOGGER.error("Problem unzipping report template: No files.");
            return;
        }
        for (int index = 0; index < files.length; index++) {
            ZipFile zipFile = null;
            try {
                String sname = files[index].getName();
                String oid = sname.substring(sname.length() - 6, sname.length() - 4);
                zipFile = new ZipFile(files[index], ZipFile.OPEN_READ);
                LOGGER.debug("Extracting template from " + files[index].getName());
                unzipFileIntoDirectory(zipFile, tmpDir);

                File descriptor = new File(tmpDir, "description.xml");
                InputStream in = new FileInputStream(descriptor);
                //parse using builder to get DOM representation of the XML file
                Map<String, Object> desc = ReportBL.getTemplateDescription(in);

                String rname = "The name";
                String description = "The description";
                String expfmt = (String) desc.get("format");

                Map<String, String> localizedStuff = (Map<String, String>) desc
                        .get("locale_" + Locale.getDefault().getLanguage());
                if (localizedStuff != null) {
                    rname = localizedStuff.get("listing");
                    description = localizedStuff.get("description");
                } else {
                    localizedStuff = (Map<String, String>) desc.get("locale_en");
                    rname = localizedStuff.get("listing");
                    description = localizedStuff.get("description");
                }

                addReportTemplateToDatabase(new Integer(oid), rname, expfmt, description);

            } catch (IOException e) {
                LOGGER.error("Problem unzipping report template " + files[index].getName());
                LOGGER.debug(ExceptionUtils.getStackTrace(e));
            }
        }
    }
}

From source file:com.plugin.excel.util.ExcelFileHelper.java

/**
 * It generates new Excel file at given locaiton
 * //from   w ww .  j  av a2  s  .  c om
 * @param directory
 * @param fileName
 * @param workbook
 */
private static void writeWorkBook(String directory, String fileName, Workbook workbook) {

    try {
        File dir = new File(directory);
        if (!dir.exists()) {
            dir.mkdir();
        }
        File file = new File(directory + "/" + fileName);
        if (file.exists()) {
            file.delete();
        }
        FileOutputStream out = new FileOutputStream(file);
        workbook.write(out);
        out.close();
    } catch (Exception e) {
        String msg = "File creation fialed for dir,fileName: " + directory + "," + fileName + e.getMessage();
        throw new IllegalStateException(msg, e);
    }

}

From source file:models.utils.FileIoUtils.java

public static void createFolder(String folderPath) {

    File theDir = new File(folderPath);

    // if the directory does not exist, create it
    if (!theDir.exists()) {
        models.utils.LogUtils.printLogNormal("creating directory: " + folderPath);
        boolean result = theDir.mkdir();
        if (result) {
            models.utils.LogUtils.printLogNormal("directory just created now " + folderPath);
        }//from w ww .  j  a  v a  2  s.  c  o  m
    } else {
        models.utils.LogUtils.printLogNormal("directory " + folderPath + " already exist");
    }

}

From source file:com.microsoft.intellij.AzurePlugin.java

private static void unzip(String zipFilePath, String destDirectory) throws IOException {
    File destDir = new File(destDirectory);
    if (!destDir.exists()) {
        destDir.mkdir();
    }/*from ww  w. j a  v  a2 s  . c o m*/
    ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
    ZipEntry entry = zipIn.getNextEntry();
    while (entry != null) {
        String filePath = destDirectory + File.separator + entry.getName();
        if (!entry.isDirectory()) {
            extractFile(zipIn, filePath);
        } else {
            File dir = new File(filePath);
            dir.mkdir();
        }
        zipIn.closeEntry();
        entry = zipIn.getNextEntry();
    }
    zipIn.close();
}

From source file:dynamicrefactoring.util.io.FileManager.java

/**
 * Intenta crear un nuevo directorio en una ruta determinada.
 * // w w  w .  j  av  a2 s .  com
 * @param path la ruta del nuevo directorio que se quiere crear.
 * 
 * @return <code>true</code> si se pudo crear el directorio; <code>false</code>
 * en caso contrario. 
 */
public static boolean createDir(String path) {
    try {
        File file = new File(path);

        return file.mkdir();
    } catch (SecurityException se) {
        return false;
    }
}

From source file:edu.iu.daal_pca.PCAUtil.java

/**
 * Generate data and upload to the data dir.
 *
 * @param numOfDataPoints//from   w  ww .  j  a  v a2  s  .co  m
 * @param vectorSize
 * @param numPointFiles
 * @param localInputDir
 * @param fs
 * @param dataDir
 * @throws IOException
 * @throws InterruptedException
 * @throws ExecutionException
 */
static void generatePoints(int numOfDataPoints, int vectorSize, int numPointFiles, String localInputDir,
        FileSystem fs, Path dataDir) throws IOException, InterruptedException, ExecutionException {
    int pointsPerFile = numOfDataPoints / numPointFiles;
    System.out.println("Writing " + pointsPerFile + " vectors to a file");
    // Check data directory
    if (fs.exists(dataDir)) {
        fs.delete(dataDir, true);
    }
    // Check local directory
    File localDir = new File(localInputDir);
    // If existed, regenerate data
    if (localDir.exists() && localDir.isDirectory()) {
        for (File file : localDir.listFiles()) {
            file.delete();
        }
        localDir.delete();
    }
    boolean success = localDir.mkdir();
    if (success) {
        System.out.println("Directory: " + localInputDir + " created");
    }
    if (pointsPerFile == 0) {
        throw new IOException("No point to write.");
    }
    // Create random data points
    int poolSize = Runtime.getRuntime().availableProcessors();
    ExecutorService service = Executors.newFixedThreadPool(poolSize);
    List<Future<?>> futures = new LinkedList<Future<?>>();
    for (int k = 0; k < numPointFiles; k++) {
        // Future<?> f = service.submit(new DataGenRunnable(pointsPerFile, localInputDir, Integer.toString(k), vectorSize));
        Future<?> f = service
                .submit(new DataGenMMDense(pointsPerFile, localInputDir, Integer.toString(k), vectorSize));
        futures.add(f); // add a new thread
    }
    for (Future<?> f : futures) {
        f.get();
    }
    // Shut down the executor service so that this
    // thread can exit
    service.shutdownNow();
    // Wrap to path object
    Path localInput = new Path(localInputDir);
    fs.copyFromLocalFile(localInput, dataDir);
    DeleteFileFolder(localInputDir);
}

From source file:com.isa.utiles.Utiles.java

/**
* Mtodo encargado de crear una carpeta. La misma
* se crea bajo la ruta absoluta pasada por parmetro.
 * @param ruta//  w  w w .jav  a 2s  .c  o m
 * @throws java.io.IOException
**/
public static void crearCarpeta(String ruta) throws IOException {
    File file = new File(ruta);
    if (!file.exists()) {
        if (!file.mkdir()) {
            throw new IOException("El directorio no existe.");
        }
    }
}

From source file:com.runwaysdk.business.generation.AbstractCompiler.java

private static boolean ensureExistence(String path) {
    if (path == null) {
        return false;
    }//from w  w w . j a  va 2  s . c  o  m

    File file = new File(path);

    if (file.exists()) {
        return true;
    }

    File parent = file.getParentFile();
    if (parent.exists()) {
        file.mkdir();
        return true;
    }

    return false;
}

From source file:eu.sisob.uma.restserver.TaskManager.java

/**
  * Create a new folder for a new task if is possible to launch new task
  * Note:/*ww w  .j  a  v  a  2 s  . c om*/
  *  use MAX_TASKS_PER_USER and validateAccess()
  *  Is possible that use thee locker of AuthorizationManager
  * @param user
  * @param pass
  * @param status
  * @param message 
  * @return
  */
public static String prepareNewTask(String user, String pass, StringWriter status, StringWriter message) {
    String new_folder_name = "";
    if (message == null)
        return "";
    message.getBuffer().setLength(0);

    if (user != null && pass != null) {
        if (AuthorizationManager.validateAccess(user, pass, message)) {
            message.getBuffer().setLength(0);
            List<String> task_code_list = TaskManager.listTasks(user, pass);

            int num_tasks_alive = 0;
            int max = -1;
            if (task_code_list.size() > 0) {
                for (String task_code : task_code_list) {
                    OutputTaskStatus task_status = TaskManager.getTaskStatus(user, pass, task_code, false,
                            false, false);
                    if (task_status.status.equals(OutputTaskStatus.TASK_STATUS_EXECUTED)) {

                    } else {
                        //Think about it
                        num_tasks_alive++;
                    }

                    try {
                        int act = Integer.parseInt(task_code);
                        if (max < act) {
                            max = act;
                        }
                    } catch (Exception ex) {

                    }

                }
            }

            if (num_tasks_alive < AuthorizationManager.MAX_TASKS_PER_USER) {
                new_folder_name = String.valueOf(max + 1);

                String code_task_folder = TASKS_USERS_PATH + File.separator + user + File.separator
                        + new_folder_name;
                File task_dir = new File(code_task_folder);
                if (!task_dir.exists()) {
                    task_dir.mkdir();
                    status.append(OutputTaskStatus.TASK_STATUS_TO_EXECUTE);
                    if (message != null)
                        message.append("A new task has been created successfully."); //FIXME
                } else {
                    new_folder_name = "";
                    status.append(OutputTaskStatus.TASK_STATUS_NO_ACCESS);
                    if (message != null)
                        message.append("Error creating place for the new task."); //FIXME
                }
            } else {
                new_folder_name = "";
                status.append(OutputTaskStatus.TASK_STATUS_EXECUTING);
                if (message != null)
                    message.append(
                            "There are still tasks running or there are a task created ready to be launched."); //FIXME
            }

        } else {
            new_folder_name = "";
            status.append(OutputTaskStatus.TASK_STATUS_NO_AUTH);
        }
    } else {
        new_folder_name = "";
        status.write(OutputTaskStatus.TASK_STATUS_NO_AUTH);
        if (message != null)
            message.write(TheResourceBundle.getString("Jsp Params Invalid Msg"));
    }

    return new_folder_name;
}

From source file:models.utils.FileIoUtils.java

public static void createFolderTestWin() {

    // win: S:\GitSources\AgentMaster\AgentMaster\AgentMaster
    // linux AgentMaster\AgentMaster
    // String applicationPath = Play.applicationPath.getAbsolutePath();
    // models.utils.LogUtils.printLogNormal(applicationPath);

    String directoryPath = "S:\\GitSources\\AgentMaster\\AgentMaster\\AgentMaster\\app_logs\\20130627";
    File theDir = new File(directoryPath);

    // if the directory does not exist, create it
    if (!theDir.exists()) {
        models.utils.LogUtils.printLogNormal("creating directory: " + directoryPath);
        boolean result = theDir.mkdir();
        if (result) {
            models.utils.LogUtils.printLogNormal("DIR created");
        }/*w w w. j a va2s.c om*/

    }

}