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.bb.extensions.plugin.unittests.internal.utilities.FileUtils.java

/**
 * Create a temp directory in a folder//from w w w.  j  a v  a2  s .  c om
 * 
 * @param file
 *            The folder to make the temp dir in
 * @return The temp directory created
 */
public static File findTempFolder(File file) {
    String baseName = System.currentTimeMillis() + "-";
    for (int counter = 0; counter < 1000; counter++) {
        File tempDir = new File(file, baseName + counter);
        if (tempDir.mkdir()) {
            return tempDir;
        }
    }
    return null;
}

From source file:gov.nasa.ensemble.dictionary.nddl.NDDLUtil.java

public static void copyDirectory(File sourceLocation, File targetLocation) throws IOException {
    if (sourceLocation.isDirectory()) {
        if (!targetLocation.exists()) {
            targetLocation.mkdir();
        }//from   w w w .jav a  2s .c o  m

        String[] children = sourceLocation.list();
        for (int i = 0; i < children.length; i++) {
            copyDirectory(new File(sourceLocation, children[i]), new File(targetLocation, children[i]));
        }
    } else {

        InputStream in = new FileInputStream(sourceLocation);
        OutputStream out = new FileOutputStream(targetLocation);
        IOUtils.copy(in, out);
        in.close();
        out.close();
    }
}

From source file:net.portalblock.untamedchat.bungee.UCConfig.java

public static void load() {
    final String NEW_LINE = System.getProperty("line.separator");
    File cfgDir = new File("plugins/UntamedChat");
    if (!cfgDir.exists()) {
        UntamedChat.getInstance().getLogger().info("No config directory found, generating one now!");
        cfgDir.mkdir();
    }//from   w  w  w . j  av  a  2 s .  co m
    File configFile = new File(cfgDir + "/config.json");
    if (!configFile.exists()) {
        UntamedChat.getInstance().getLogger().info("No config file found, generating one now!");
        try {
            configFile.createNewFile();
            InputStream is = UCConfig.class.getResourceAsStream("/config.json");
            String line;
            if (is == null)
                throw new NullPointerException("is");
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            FileWriter configWriter = new FileWriter(configFile);
            while ((line = reader.readLine()) != null) {
                configWriter.write(line + NEW_LINE);
            }
            configWriter.flush();
            configWriter.close();
            reader.close();
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    try {
        BufferedReader reader = new BufferedReader(new FileReader(configFile));
        StringBuilder configBuilder = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            configBuilder.append(line);
        }
        JSONObject config = new JSONObject(configBuilder.toString());
        TARGET_FORMAT = config.optString("target_format", "&6{sender} &7-> &6Me&7: {msg}");
        SENDER_FORMAT = config.optString("sender_format", "&6Me &7-> &6{target}&7: {msg}");
        SOCIAL_SPY_FORMAT = config.optString("social_spy_format", "{sender} -> {target}: {msg}");
        GLOBAL_FORMAT = config.optString("global_format", "&7[&6{server}&7] [&6{sender}&7]: &r{msg}");
        gcDefault = config.optBoolean("global_chat_default", false);
        chatCoolDowns = config.optBoolean("enable_chat_cooldown", true);
        spDefault = config.optBoolean("social_spy_default", false);
        chatCooldown = config.optLong("chat_cooldown", 10);
        SPAM_MESSAGE = config.optString("spam_message", "&7[&cUntamedChat&7] &cDon't spam the chat!");
        JSONObject commands = config.optJSONObject("commands");
        if (commands == null) {
            msgAliases = new String[] { "msg", "m" };
            replyAliases = new String[] { "reply", "r" };
            globalAliases = new String[] { "globalchat", "global", "g" };
            socialSpyAliases = new String[] { "socialspy", "sp", "spy" };
        } else {
            msgAliases = makeCommandArray(commands.optJSONArray("msg"), "msg", "m");
            replyAliases = makeCommandArray(commands.optJSONArray("reply"), "reply", "r");
            globalAliases = makeCommandArray(commands.optJSONArray("global_chat"), "globalchat", "global", "g");
            socialSpyAliases = makeCommandArray(commands.optJSONArray("social_spy"), "socialspy", "sp", "spy");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.catalyst.sonar.score.batch.util.FileInstaller.java

/**
 * Copies files recursively, meaning that if the files are directories,
 * their contents will also be copied./*from  w ww  . j  av  a 2 s .c o m*/
 * 
 * @param toCopy
 * @param destDir
 * @return true if copy is successful, false otherwise.
 */
private static boolean copyFilesRecusively(final File toCopy, final File destDir) {
    assert destDir.isDirectory();
    logger.debug("copyFilesRecursively()");
    boolean success = true;
    if (!toCopy.isDirectory()) {
        success = FileInstaller.copyFile(toCopy, new File(destDir, toCopy.getName()));
        logger.debug("returning " + success);
        return success;
    } else {
        final File newDestDir = new File(destDir, toCopy.getName());
        if (!newDestDir.exists() && !newDestDir.mkdir()) {
            success = false;
            logger.debug("returning " + success);
            return success;
        }
        for (final File child : toCopy.listFiles()) {
            if (!FileInstaller.copyFilesRecusively(child, newDestDir)) {
                success = false;
                logger.debug("returning " + success);
                return success;
            }
        }
    }
    logger.debug("returning " + success);
    return success;
}

From source file:com.mgmtp.perfload.perfalyzer.util.IoUtilities.java

/**
 * Creates a temporary directory named with a random UUID in the directory specified by the
 * system property {@coe java.io.tmpdir}.
 *
 * @return the directory/*  ww  w  . j ava 2s  .c  o  m*/
 */
public static File createTempDir() {
    File file = new File(SystemUtils.JAVA_IO_TMPDIR, UUID.randomUUID().toString());
    checkState(file.mkdir(), "Could not create temporary directory %s", file);
    return file;
}

From source file:com.sitewhere.configuration.TomcatConfigurationResolver.java

/**
 * Gets the CATALINA/data folder where data is stored.
 * // w ww.ja v  a  2s . c  o m
 * @return
 * @throws SiteWhereException
 */
public static File getSiteWhereDataFolder() throws SiteWhereException {
    String catalina = System.getProperty("catalina.base");
    if (catalina == null) {
        throw new SiteWhereException("CATALINA_HOME not set.");
    }
    File catFolder = new File(catalina);
    if (!catFolder.exists()) {
        throw new SiteWhereException("CATALINA_HOME folder does not exist.");
    }
    File dataDir = new File(catalina, "data");
    if (!dataDir.exists()) {
        dataDir.mkdir();
    }
    return dataDir;
}

From source file:com.ruesga.rview.misc.CacheHelper.java

@SuppressWarnings("ResultOfMethodCallIgnored")
public static File getImagesCacheDir(Context context) {
    File cacheDir = new File(context.getCacheDir(), IMAGES_CACHE_FOLDER);
    if (!cacheDir.exists()) {
        cacheDir.mkdir();
    }/*from www.jav a  2  s  . c o m*/
    return cacheDir;
}

From source file:net.fabricmc.loom.task.DownloadTask.java

private static boolean deleteIfExists(File file) {
    if (file.exists()) {
        if (file.isDirectory()) {
            try {
                FileUtils.deleteDirectory(file);
                return file.mkdir();
            } catch (IOException e) {
                e.printStackTrace();/*w w  w . j a v  a 2s.c  o  m*/
            }
        }
        return file.delete();
    }
    return false;
}

From source file:com.stratio.crossdata.sh.utils.ConsoleUtils.java

/**
 * Get previous history of the Crossdata console from a file.
 *
 * @param console Crossdata console created from a JLine console
 * @param sdf     Simple Date Format to read dates from history file
 * @return File inserted in the JLine console with the previous history
 * @throws IOException// w ww.ja va 2 s .  c o m
 */
public static File retrieveHistory(ConsoleReader console, SimpleDateFormat sdf) throws IOException {
    Date today = new Date();
    String workingDir = System.getProperty("user.home");
    File dir = new File(workingDir, ".com.stratio.crossdata");
    if (!dir.exists() && !dir.mkdir()) {
        LOG.error("Cannot create history directory: " + dir.getAbsolutePath());
    }
    File file = new File(dir.getPath() + "/history.txt");
    if (!file.exists() && !file.createNewFile()) {
        LOG.error("Cannot create history file: " + file.getAbsolutePath());
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("Retrieving history from " + file.getAbsolutePath());
    }
    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
    History oldHistory = new MemoryHistory();
    DateTime todayDate = new DateTime(today);
    String line;
    String[] lineArray;
    Date lineDate;
    String lineStatement;
    try {
        while ((line = br.readLine()) != null) {
            lineArray = line.split("\\|");
            lineDate = sdf.parse(lineArray[0]);
            if (Days.daysBetween(new DateTime(lineDate), todayDate).getDays() < DAYS_HISTORY_ENTRY_VALID) {
                lineStatement = lineArray[1];
                oldHistory.add(lineStatement);
            }
        }
    } catch (ParseException ex) {
        LOG.error("Cannot parse date", ex);
    } catch (Exception ex) {
        LOG.error("Cannot read all the history", ex);
    } finally {
        br.close();
    }
    console.setHistory(oldHistory);
    LOG.info("History retrieved");
    return file;
}

From source file:com.ruesga.rview.misc.CacheHelper.java

@SuppressWarnings("ResultOfMethodCallIgnored")
public static File getAttachmentCacheDir(Context context) {
    File cacheDir = new File(context.getCacheDir(), ATTACHMENT_CACHE_FOLDER);
    if (!cacheDir.exists()) {
        cacheDir.mkdir();
    }//from w ww .ja va2  s. com
    return cacheDir;
}