How To Create A New Directory In Java
Best Java code snippets using java.io.File.mkdir (Showing top 20 results out of 74,790)
Refine search
- Common ways to obtain File
private void myMethod ()
{
}
File folder = new File (Environment.getExternalStorageDirectory() + "/map" ); boolean success = true ; if (!folder. exists ()) { success = folder. mkdir (); } if (success) { } else { }
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; }
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); } }
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; }
@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>" ); }
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);
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 (); }
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(); } }
@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." ); } }
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); }
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; }
private static void makeDir(String path) { File outDir = new File (path); if (!outDir. exists ()) { outDir. mkdir (); } }
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 )); }
@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>" ); }
protected void initLaunchDir() { initLaunchId(); try { currentLaunchDir = new File (getConfigurationFile().getParentFile(), getCurrentLaunchId()); if (!currentLaunchDir. mkdir ()) { throw new IOException( "failed to create directory " + currentLaunchDir); } FileUtils.copyFileToDirectory(getConfigurationFile(), currentLaunchDir); 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; } }
@Override protected AbstractDirectory createDirLocal(String name) throws DirectoryException { File dir = new File (generatePath(name)); dir. mkdir (); return new FileDirectory(dir); }
private void makeSureIsDirectory(File dir) throws IOException { if (!dir. isDirectory ()) { boolean success; if (dir. exists ()) { 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()); } } }
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); } }
private void makeArtifactoryCache(String location) throws IOException { 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 ; }
File theDir = new File ( "new folder" ); if (!theDir. exists ()) { System.out.println( "creating directory: " + directoryName); boolean result = false ; try { theDir. mkdir (); result = true ; } catch (SecurityException se){ } if (result) { System.out.println( "DIR created" ); } }
How To Create A New Directory In Java
Source: https://www.tabnine.com/code/java/methods/java.io.File/mkdir
Posted by: kennedyweds2000.blogspot.com
0 Response to "How To Create A New Directory In Java"
Post a Comment