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

How to use
mkdirs
method
in
java.io.File

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

Refine searchRefine arrow

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

 // Create a directory; all non-existent ancestor directories are
// automatically created
success = (new File("../potentially/long/pathname/without/all/dirs")).mkdirs();
if (!success) {
  // Directory creation failed
}
origin: stackoverflow.com

 // create a File object for the parent directory
File wallpaperDirectory = new File("/sdcard/Wallpaper/");
// have the object build the directory structure, if needed.
wallpaperDirectory.mkdirs();
// create a File object for the output file
File outputFile = new File(wallpaperDirectory, filename);
// now attach the OutputStream to the file object, instead of a String representation
FileOutputStream fos = new FileOutputStream(outputFile);
origin: Blankj/AndroidUtilCode

private static boolean createOrExistsDir(final File file) {
  return file != null && (file.exists() ? file.isDirectory() : file.mkdirs());
}
origin: Tencent/tinker

public InfoWriter(Configuration config, String infoPath) throws IOException {
  this.config = config;
  this.infoPath = infoPath;
  if (infoPath != null) {
    this.infoFile = new File(infoPath);
    if (!infoFile.getParentFile().exists()) {
      infoFile.getParentFile().mkdirs();
    }
  } else {
    this.infoFile = null;
  }
}
origin: androidannotations/androidannotations

private File ensureOutputDirectory() {
  File outputDir = new File(OUTPUT_DIRECTORY);
  if (!outputDir.exists()) {
    outputDir.mkdirs();
  }
  return outputDir;
}
origin: neo4j/neo4j

  @Override
  File ensureDirectoryExists( FileSystemAbstraction fileSystem, File dir )
  {
    if ( !dir.exists() && !dir.mkdirs() )
    {
      String message = String.format( "Unable to create directory path[%s] for Neo4j store" + ".",
          dir.getAbsolutePath() );
      throw new RuntimeException( message );
    }
    return dir;
  }
},
origin: stackoverflow.com

 File file = new File("C:\\user\\Desktop\\dir1\\dir2\\filename.txt");
file.getParentFile().mkdirs();
FileWriter writer = new FileWriter(file);
origin: gocd/gocd

  @Test
  public void shouldNotValidateNestingOfMaterialDirectoriesBasedOnServerSideFileSystem() throws IOException {
    final File workingDir = temporaryFolder.newFolder("go-working-dir");
    final File material1 = new File(workingDir, "material1");
    material1.mkdirs();

    final Path material2 = Files.createSymbolicLink(Paths.get(new File(workingDir, "material2").getPath()), Paths.get(material1.getPath()));

    material.setFolder(material1.getAbsolutePath());
    material.validateNotSubdirectoryOf(material2.toAbsolutePath().toString());

    assertNull(material.errors().getAllOn(FOLDER));
  }
}
origin: Tencent/tinker

public static void ensureFileDirectory(File file) {
  if (file == null) {
    return;
  }
  File parentFile = file.getParentFile();
  if (!parentFile.exists()) {
    parentFile.mkdirs();
  }
}
origin: jenkinsci/jenkins

public void mkdirs() {
  file.getParentFile().mkdirs();
}
origin: gocd/gocd

public void streamToFile(InputStream stream, File dest) throws IOException {
  dest.getParentFile().mkdirs();
  FileOutputStream out = new FileOutputStream(dest, true);
  try {
    IOUtils.copyLarge(stream, out);
  } finally {
    IOUtils.closeQuietly(out);
  }
}
origin: stackoverflow.com

 File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/dir1/dir2");
dir.mkdirs();
File file = new File(dir, "filename");

FileOutputStream f = new FileOutputStream(file);
...
origin: Tencent/tinker

/**
 * create directory
 *
 * @param directoryPath
 */
public static void createDirectory(final String directoryPath) {
  File file = new File(directoryPath);
  if (!file.exists()) {
    file.setReadable(true, false);
    file.setWritable(true, true);
    file.mkdirs();
  }
}
origin: jenkinsci/jenkins

/**
 * Rewrite log file.
 */
protected File getLogFile() {
  File base = getBaseDir();
  base.mkdirs();
  return new File(base,"log");
}
origin: org.testng/testng

private void addOutputDir(List<String> argv) {
 if (null != m_outputDir) {
  if (!m_outputDir.exists()) {
   m_outputDir.mkdirs();
  }
  if (m_outputDir.isDirectory()) {
   argv.add(CommandLineArgs.OUTPUT_DIRECTORY);
   argv.add(m_outputDir.getAbsolutePath());
  } else {
   throw new BuildException("Output directory is not a directory: " + m_outputDir);
  }
 }
}
origin: stackoverflow.com

 String path = "C:" + File.separator + "hello" + File.separator + "hi.txt";
// Use relative path for Unix systems
File f = new File(path);

f.getParentFile().mkdirs(); 
f.createNewFile();
origin: libgdx/libgdx

  @Override
  protected void processDir (Entry entryDir, ArrayList<Entry> value) throws Exception {
    if (!entryDir.outputDir.exists()) {
      if (!entryDir.outputDir.mkdirs())
        throw new Exception("Couldn't create output directory '" + entryDir.outputDir + "'");
    }
  }
}
origin: gocd/gocd

  @Test
  public void shouldNotValidateNestingOfMaterialDirectoriesBasedOnServerSideFileSystem() throws IOException {
    final File workingDir = temporaryFolder.newFolder("go-working-dir");
    final File material1 = new File(workingDir, "material1");
    material1.mkdirs();

    final Path material2 = Files.createSymbolicLink(Paths.get(new File(workingDir, "material2").getPath()), Paths.get(material1.getPath()));

    pluggableSCMMaterialConfig.setFolder(material1.getAbsolutePath());
    pluggableSCMMaterialConfig.validateNotSubdirectoryOf(material2.toAbsolutePath().toString());

    assertNull(pluggableSCMMaterialConfig.errors().getAllOn(FOLDER));
  }
}
origin: apache/flink

public String createTempFile(String fileName, String contents) throws IOException {
  File f = createAndRegisterTempFile(fileName);
  if (!f.getParentFile().exists()) {
    f.getParentFile().mkdirs();
  }
  f.createNewFile();
  FileUtils.writeFileUtf8(f, contents);
  return f.toURI().toString();
}
origin: jenkinsci/jenkins

public void on() {
  try {
    file.getParentFile().mkdirs();
    Files.newOutputStream(file.toPath()).close();
    get();  // update state
  } catch (IOException | InvalidPathException e) {
    LOGGER.log(Level.WARNING, "Failed to touch "+file);
  }
}
java.ioFilemkdirs

Javadoc

Creates the directory named by this file, creating missing parent directories if necessary. Use #mkdir if you don't 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.mkdirs() || 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
  • 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
  • toURI
  • length,
  • toURI,
  • createTempFile,
  • createNewFile,
  • toPath,
  • mkdir,
  • lastModified,
  • toString,
  • getCanonicalPath

Popular in Java

  • Start an intent from android
  • scheduleAtFixedRate (Timer)
  • runOnUiThread (Activity)
  • getSharedPreferences (Context)
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • 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