Tabnine Logo
File.mkdir
Code IndexAdd Tabnine to your IDE (free)

How to use
mkdir
method
in
java.io.File

Best Java code snippets using java.io.File.mkdir (Showing top 20 results out of 74,790)

Refine searchRefine arrow

  • File.<init>
  • File.exists
  • FileOutputStream.<init>
  • File.getAbsolutePath
  • File.isDirectory
  • File.getName
origin: stackoverflow.com

 File folder = new File(Environment.getExternalStorageDirectory() + "/map");
boolean success = true;
if (!folder.exists()) {
  success = folder.mkdir();
}
if (success) {
  // Do something on success
} else {
  // Do something else on failure 
}
origin: thinkaurelius/titan

private static File getSubDirectory(String base, String sub) {
  File subdir = new File(base, sub);
  if (!subdir.exists()) {
    if (!subdir.mkdir()) {
      throw new IllegalArgumentException("Cannot create subdirectory: " + sub);
    }
  }
  assert subdir.exists() && subdir.isDirectory();
  return subdir;
}
origin: redisson/redisson

/**
 * Creates single folders.
 */
public static void mkdir(File dir) throws IOException {
  if (dir.exists()) {
    if (!dir.isDirectory()) {
      throw new IOException(MSG_NOT_A_DIRECTORY + dir);
    }
    return;
  }
  if (!dir.mkdir()) {
    throw new IOException(MSG_CANT_CREATE + dir);
  }
}
origin: Alluxio/alluxio

/**
 * Creates a directory with the given prefix inside the Alluxio temporary directory.
 *
 * @param prefix a prefix to use in naming the temporary directory
 * @return the created directory
 */
public static File createTemporaryDirectory(String prefix) {
 final File file = new File(ALLUXIO_TEST_DIRECTORY, prefix + "-" + UUID.randomUUID());
 if (!file.mkdir()) {
  throw new RuntimeException("Failed to create directory " + file.getAbsolutePath());
 }
 Runtime.getRuntime().addShutdownHook(new Thread(() -> delete(file)));
 return file;
}
origin: testcontainers/testcontainers-java

@BeforeClass
public static void setupContent() throws FileNotFoundException {
  contentFolder.mkdir();
  contentFolder.setReadable(true, false);
  contentFolder.setWritable(true, false);
  contentFolder.setExecutable(true, false);
  File indexFile = new File(contentFolder, "index.html");
  indexFile.setReadable(true, false);
  indexFile.setWritable(true, false);
  indexFile.setExecutable(true, false);
  @Cleanup PrintStream printStream = new PrintStream(new FileOutputStream(indexFile));
  printStream.println("<html><body>This worked</body></html>");
}
origin: stanfordnlp/CoreNLP

boolean createdDir = (new File(distribName)).mkdir();
if(createdDir) {
   File destFile = new File(filename);
   String relativePath = distribName + "/" + destFile.getName();
   destFile = new File(relativePath);
   FileSystem.copyFile(new File(filename),destFile);
origin: apache/flink

JobArchiveFetcherTask(List<HistoryServer.RefreshLocation> refreshDirs, File webDir, CountDownLatch numFinishedPolls) {
  this.refreshDirs = checkNotNull(refreshDirs);
  this.numFinishedPolls = numFinishedPolls;
  this.cachedArchives = new HashSet<>();
  this.webDir = checkNotNull(webDir);
  this.webJobDir = new File(webDir, "jobs");
  webJobDir.mkdir();
  this.webOverviewDir = new File(webDir, "overviews");
  webOverviewDir.mkdir();
}
origin: kiegroup/optaplanner

public void initBenchmarkReportDirectory(File benchmarkDirectory) {
  String timestampString = startingTimestamp.format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss"));
  if (StringUtils.isEmpty(name)) {
    name = timestampString;
  }
  if (!benchmarkDirectory.mkdirs()) {
    if (!benchmarkDirectory.isDirectory()) {
      throw new IllegalArgumentException("The benchmarkDirectory (" + benchmarkDirectory
          + ") already exists, but is not a directory.");
    }
    if (!benchmarkDirectory.canWrite()) {
      throw new IllegalArgumentException("The benchmarkDirectory (" + benchmarkDirectory
          + ") already exists, but is not writable.");
    }
  }
  int duplicationIndex = 0;
  do {
    String directoryName = timestampString + (duplicationIndex == 0 ? "" : "_" + duplicationIndex);
    duplicationIndex++;
    benchmarkReportDirectory = new File(benchmarkDirectory,
        BooleanUtils.isFalse(aggregation) ? directoryName : directoryName + "_aggregation");
  } while (!benchmarkReportDirectory.mkdir());
  for (ProblemBenchmarkResult problemBenchmarkResult : unifiedProblemBenchmarkResultList) {
    problemBenchmarkResult.makeDirs();
  }
}
origin: apache/flink

@Before
public void setUp() throws Exception {
  final File testRoot = folder.newFolder();
  checkpointDir = new File(testRoot, "checkpoints");
  savepointDir = new File(testRoot, "savepoints");
  if (!checkpointDir.mkdir() || !savepointDir.mkdirs()) {
    fail("Test setup failed: failed to create temporary directories.");
  }
}
origin: stackoverflow.com

 public static File createTempDirectory()
  throws IOException
{
  final File temp;

  temp = File.createTempFile("temp", Long.toString(System.nanoTime()));

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

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

  return (temp);
}
origin: azkaban/azkaban

private static File createIfDoesNotExist(final String baseDirectoryPath) {
 final File baseDirectory = new File(baseDirectoryPath);
 if (!baseDirectory.exists()) {
  baseDirectory.mkdir();
  log.info("Creating dir: " + baseDirectory.getAbsolutePath());
 }
 return baseDirectory;
}
origin: stanfordnlp/CoreNLP

private static void makeDir(String path) {
 File outDir = new File(path);
 if (!outDir.exists()) {
   outDir.mkdir();
 }
}
origin: prestodb/presto

EmbeddedElasticsearchNode()
{
  try {
    elasticsearchDirectory = File.createTempFile("elasticsearch", "test");
    elasticsearchDirectory.delete();
    elasticsearchDirectory.mkdir();
  }
  catch (IOException e) {
    throw new UncheckedIOException(e);
  }
  Settings setting = Settings.builder()
      .put("cluster.name", "test")
      .put("path.home", elasticsearchDirectory.getPath())
      .put("path.data", new File(elasticsearchDirectory, "data").getAbsolutePath())
      .put("path.logs", new File(elasticsearchDirectory, "logs").getAbsolutePath())
      .put("transport.type.default", "local")
      .put("transport.type", "netty4")
      .put("http.type", "netty4")
      .put("http.enabled", "true")
      .put("path.home", "elasticsearch-test-data")
      .build();
  node = new ElasticsearchNode(setting, ImmutableList.of(Netty4Plugin.class));
}
origin: testcontainers/testcontainers-java

@SuppressWarnings({"Duplicates", "ResultOfMethodCallIgnored"})
@BeforeClass
public static void setupContent() throws FileNotFoundException {
  contentFolder.mkdir();
  contentFolder.setReadable(true, false);
  contentFolder.setWritable(true, false);
  contentFolder.setExecutable(true, false);
  File indexFile = new File(contentFolder, "index.html");
  indexFile.setReadable(true, false);
  indexFile.setWritable(true, false);
  indexFile.setExecutable(true, false);
  @Cleanup PrintStream printStream = new PrintStream(new FileOutputStream(indexFile));
  printStream.println("<html><body>This worked</body></html>");
}
origin: internetarchive/heritrix3

protected void initLaunchDir() {
  initLaunchId();
  try {
    currentLaunchDir = new File(getConfigurationFile().getParentFile(), getCurrentLaunchId());
    if (!currentLaunchDir.mkdir()) {
      throw new IOException("failed to create directory " + currentLaunchDir);
    }
    
    // copy cxml to launch dir
    FileUtils.copyFileToDirectory(getConfigurationFile(), currentLaunchDir);
    
    // attempt to symlink "latest" to launch dir
    File latestSymlink = new File(getConfigurationFile().getParentFile(), "latest");
    latestSymlink.delete();
    boolean success = FilesystemLinkMaker.makeSymbolicLink(currentLaunchDir.getName(), latestSymlink.getPath());
    if (!success) {
      LOGGER.warning("failed to create symlink from " + latestSymlink + " to " + currentLaunchDir);
    }
  } catch (IOException e) {
    LOGGER.log(Level.SEVERE, "failed to initialize launch directory: " + e);
    currentLaunchDir = null;
  }
}
 
origin: iBotPeaches/Apktool

@Override
protected AbstractDirectory createDirLocal(String name) throws DirectoryException {
  File dir = new File(generatePath(name));
  dir.mkdir();
  return new FileDirectory(dir);
}
origin: marytts/marytts

private void makeSureIsDirectory(File dir) throws IOException {
  if (!dir.isDirectory()) {
    boolean success;
    if (dir.exists()) { // exists, but is not a directory
      success = dir.delete();
      if (!success) {
        throw new IOException("Need to create directory " + dir.getPath()
            + ", but file exists that cannot be deleted.");
      }
    }
    success = dir.mkdir();
    if (!success) {
      throw new IOException("Cannot create directory " + dir.getPath());
    }
  }
}
origin: iBotPeaches/Apktool

public static File createTempDirectory() throws BrutException {
  try {
    File tmp = File.createTempFile("BRUT", null);
    tmp.deleteOnExit();
    if (!tmp.delete()) {
      throw new BrutException("Could not delete tmp file: " + tmp.getAbsolutePath());
    }
    if (!tmp.mkdir()) {
      throw new BrutException("Could not create tmp dir: " + tmp.getAbsolutePath());
    }
    return tmp;
  } catch (IOException ex) {
    throw new BrutException("Could not create tmp dir", ex);
  }
}
origin: apache/storm

private void makeArtifactoryCache(String location) throws IOException {
  // First make the cache dir
  String localDirName = ServerConfigUtils.masterLocalDir(conf) + File.separator + LOCAL_ARTIFACT_DIR;
  File dir = new File(localDirName);
  if (!dir.exists()) {
    dir.mkdirs();
  }
  localCacheDir = localDirName + File.separator + location.replaceAll(File.separator, "_");
  dir = new File(localCacheDir);
  if (!dir.exists()) {
    dir.mkdir();
  }
  cacheInitialized = true;
}
origin: stackoverflow.com

 File theDir = new File("new folder");

// if the directory does not exist, create it
if (!theDir.exists()) {
  System.out.println("creating directory: " + directoryName);
  boolean result = false;

  try{
    theDir.mkdir();
    result = true;
  } 
  catch(SecurityException se){
    //handle it
  }        
  if(result) {    
    System.out.println("DIR created");  
  }
}
java.ioFilemkdir

Javadoc

Creates the directory named by this file, assuming its parents exist. Use #mkdirs if you also want to create missing parents.

Note that this method does not throw IOException on failure. Callers must check the return value. Note also that this method returns false if the directory already existed. If you want to know whether the directory exists on return, either use (f.mkdir() || f.isDirectory())or simply ignore the return value from this method and simply call #isDirectory.

Popular methods of File

  • <init>
    Creates a new File instance by converting the givenfile: URI into an abstract pathname. The exact fo
  • exists
    Tests whether the file or directory denoted by this abstract pathname exists.
  • getAbsolutePath
    Returns the absolute pathname string of this abstract pathname. If this abstract pathname is already
  • getName
    Returns the name of the file or directory denoted by this abstract pathname. This is just the last n
  • isDirectory
  • mkdirs
  • delete
    Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a director
  • listFiles
    Returns an array of abstract pathnames denoting the files and directories in the directory denoted b
  • getParentFile
    Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not
  • getPath
    Converts this abstract pathname into a pathname string. The resulting string uses the #separator to
  • isFile
  • length
    Returns the length of the file denoted by this abstract pathname. The return value is unspecified if
  • isFile,
  • length,
  • toURI,
  • createTempFile,
  • createNewFile,
  • toPath,
  • lastModified,
  • toString,
  • getCanonicalPath

Popular in Java

  • Running tasks concurrently on multiple threads
  • findViewById (Activity)
  • setRequestProperty (URLConnection)
  • getSharedPreferences (Context)
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • JLabel (javax.swing)
  • JOptionPane (javax.swing)
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now