// 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);
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; } }
@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; } },
File file = new File("C:\\user\\Desktop\\dir1\\dir2\\filename.txt"); file.getParentFile().mkdirs(); FileWriter writer = new FileWriter(file);
@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)); } }
public static void ensureFileDirectory(File file) { if (file == null) { return; } File parentFile = file.getParentFile(); if (!parentFile.exists()) { parentFile.mkdirs(); } }
public void mkdirs() { file.getParentFile().mkdirs(); }
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); } }
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); ...
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); } } }
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();
@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)); } }
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(); }
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); } }