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.smartsheet.tools.SmartsheetBackupService.java

private static File createNewFolderQuietly(File parentFolder, String newFolderName)
        throws CreateFileSystemItemException {
    File newFolder = new File(parentFolder, SheetSaver.scrubName(newFolderName));

    if (!newFolder.mkdir())
        throw new CreateFileSystemItemException(newFolder);
    return newFolder;
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.PropertiesTest.java

/**
 * Returns the 'artifacts' directory.//from   ww w  .j  a v a2s  . c  o m
 * @return the 'artifacts' directory
 */
public static String getArtifactsDirectory() {
    final String dirName = "./artifacts";
    final File dir = new File(dirName);
    if (!dir.exists()) {
        if (!dir.mkdir()) {
            throw new RuntimeException("Could not create artifacts directory");
        }
    }
    return dirName;
}

From source file:core.service.RubricImageCachingService.java

public static void createFolders(File dst, List<? extends Pages> pages) {
    File dst_dir;/*from   www  .  j a  v  a 2  s.co  m*/
    if (!dst.exists() || dst.isFile()) {
        dst.delete();
        dst.mkdir();
    }
    for (Pages p : pages) {
        dst_dir = new File(dst, p.getId().toString());
        if (!dst_dir.exists())
            dst_dir.mkdir();
    }
}

From source file:UtilFunctions.java

public static File makeDirectory(File parentDirectory, String newDirectoryName) {
    try {/* ww w  . j  a v a  2s. c o m*/
        File newDirectory = new File(parentDirectory.getCanonicalPath() + "/" + newDirectoryName + "/");
        int i = 0;

        while (newDirectory.exists()) {
            newDirectory = new File(parentDirectory.getCanonicalPath() + "/" + newDirectoryName + i + "/");
            i++;
        }

        newDirectory.mkdir();

        return newDirectory;

    } catch (IOException ex) {
        Logger.getLogger(UtilFunctions.class.getName()).log(Level.SEVERE, null, ex);
        return parentDirectory;
    }

}

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

/**
 * Migrate assets and scripts into template directory.
 * /*from w w  w .  j  a  v  a 2  s  . c  om*/
 * @param root
 * @param templateFolder
 * @throws SiteWhereException
 */
protected static void migrateResources(File root, File templateFolder) throws SiteWhereException {
    // Move assets.
    File assets = new File(root, "assets");
    if (assets.exists()) {
        try {
            File newAssets = new File(templateFolder, FileSystemTenantConfigurationResolver.ASSETS_FOLDER);
            FileUtils.moveDirectory(assets, newAssets);
        } catch (IOException e) {
            throw new SiteWhereException("Unable to move assets folder to template.");
        }
    }

    // Move Groovy scripts.
    File scripts = new File(templateFolder, FileSystemTenantConfigurationResolver.SCRIPTS_FOLDER);
    if (!scripts.exists()) {
        if (!scripts.mkdir()) {
            throw new SiteWhereException("Unable to create scripts folder in template folder.");
        }
        try {
            File groovy = new File(root, "groovy");
            if (groovy.exists()) {
                File newGroovy = new File(scripts, "groovy");
                FileUtils.moveDirectory(groovy, newGroovy);
            }
        } catch (IOException e) {
            throw new SiteWhereException("Unable to move assets folder to template.");
        }
    }
}

From source file:com.googlecode.fightinglayoutbugs.helpers.FileHelper.java

public static File createTempDir() throws IOException {
    final File baseDir = new File(System.getProperty("java.io.tmpdir"));
    if (!baseDir.isDirectory()) {
        throw new IOException("java.io.tmpdir (" + baseDir + ") is not a directory.");
    }/*from   w  w  w .  j a va 2  s  . c  o  m*/
    final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    int i = 0;
    while (!stackTrace[i].getClassName().equals(FileHelper.class.getName())) {
        ++i;
    }
    while (stackTrace[i].getClassName().equals(FileHelper.class.getName())) {
        ++i;
    }
    String prefix = stackTrace[i].getClassName();
    prefix = prefix.substring(prefix.lastIndexOf('.') + 1);
    File tempDir;
    boolean tempDirSuccessfullyCreated;
    do {
        final long randomLong = LazyInitRandom.nextLong();
        final String dirName = prefix + (randomLong < 0 ? randomLong : "-" + randomLong);
        tempDir = new File(baseDir, dirName);
        tempDirSuccessfullyCreated = !tempDir.exists() && tempDir.mkdir();
    } while (!tempDirSuccessfullyCreated);
    return tempDir;
}

From source file:de.hpi.fgis.hdrs.node.Index.java

public static Index createIndex(File indexRoot, Triple.COLLATION order, SegmentIdGenerator idGen)
        throws IOException {
    if (!indexRoot.mkdir()) {
        throw new IOException("Couldn't create index root directory.");
    }//from  w w  w  .  j  a va2  s  . c  o m
    Index index = new Index(indexRoot, order, idGen);
    index.writeMeta();
    return index;
}

From source file:dataflow.examples.DockerClientExample.java

static private String createLocalTempDir() {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd-HHmmss");
    Date date = new Date();
    String timestamp = formatter.format(date);

    // TODO(jlewi): Is there a java function we could use?
    File temp = null;
    try {/* ww  w.j a v  a  2 s  .c  o m*/
        temp = File.createTempFile("temp-" + timestamp + "-", "");
    } catch (IOException exception) {
        logger.error("Could not create temporary file.", exception);
        System.exit(-1);
    }

    if (!(temp.delete())) {
        throw new RuntimeException("Could not delete temp file: " + temp.getAbsolutePath());
    }

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

From source file:com.andrew.apollo.cache.ImageFetcher.java

/**
 * Download a {@link Bitmap} from a URL, write it to a disk and return the
 * File pointer. This implementation uses a simple disk cache.
 *
 * @param context The context to use/* www .  j a  v a2s. c o  m*/
 * @param urlString The URL to fetch
 * @return A {@link File} pointing to the fetched bitmap
 */
public static final File downloadBitmapToFile(final Context context, final String urlString,
        final String uniqueName) {
    final File cacheDir = ImageCache.getDiskCacheDir(context, uniqueName);

    if (!cacheDir.exists()) {
        cacheDir.mkdir();
    }

    HttpURLConnection urlConnection = null;
    BufferedOutputStream out = null;

    try {
        final File tempFile = File.createTempFile("bitmap", null, cacheDir); //$NON-NLS-1$

        final URL url = new URL(urlString);
        urlConnection = (HttpURLConnection) url.openConnection();
        if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) {
            return null;
        }
        final InputStream in = new BufferedInputStream(urlConnection.getInputStream(), IO_BUFFER_SIZE_BYTES);
        out = new BufferedOutputStream(new FileOutputStream(tempFile), IO_BUFFER_SIZE_BYTES);

        int oneByte;
        while ((oneByte = in.read()) != -1) {
            out.write(oneByte);
        }
        return tempFile;
    } catch (final IOException ignored) {
        ignored.printStackTrace();
    } finally {
        if (urlConnection != null) {
            urlConnection.disconnect();
        }
        if (out != null) {
            try {
                out.close();
            } catch (final IOException ignored) {
            }
        }
    }
    return null;
}

From source file:edu.unc.lib.dl.util.FileUtils.java

public static File createTempDirectory(String prefix) throws IOException {
    final File temp;
    temp = File.createTempFile(prefix, Long.toString(System.nanoTime()));
    if (!(temp.delete())) {
        throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
    }//w  ww  .  j a v  a2  s . co  m
    if (!(temp.mkdir())) {
        throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
    }
    return (temp);
}