java.nio.file.Files.createDirectories()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(602)

本文整理了Java中java.nio.file.Files.createDirectories()方法的一些代码示例,展示了Files.createDirectories()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.createDirectories()方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:createDirectories

Files.createDirectories介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
  Files.createDirectories(dest.resolve(src.relativize(dir)));
  return FileVisitResult.CONTINUE;
}
@Override

代码示例来源:origin: Alluxio/alluxio

/**
 * Creates an empty directory and its intermediate directories if necessary.
 *
 * @param path path of the directory to create
 */
public static void createDir(String path) throws IOException {
 Files.createDirectories(Paths.get(path));
}

代码示例来源:origin: pxb1988/dex2jar

public static void createParentDirectories(Path p) throws IOException {
  // merge patch from t3stwhat, fix crash on save to windows path like 'C:\\abc.jar'
  Path parent = p.getParent();
  if (parent != null && !Files.exists(parent)) {
    Files.createDirectories(parent);
  }
}

代码示例来源:origin: prestodb/presto

public static void writePluginServices(Iterable<String> plugins, File root)
    throws IOException
{
  Path path = root.toPath().resolve(SERVICES_FILE);
  createDirectories(path.getParent());
  try (Writer out = new OutputStreamWriter(new FileOutputStream(path.toFile()), UTF_8)) {
    for (String plugin : plugins) {
      out.write(plugin + "\n");
    }
  }
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Creates an empty file and its intermediate directories if necessary.
 *
 * @param filePath pathname string of the file to create
 */
public static void createFile(String filePath) throws IOException {
 Path storagePath = Paths.get(filePath);
 Files.createDirectories(storagePath.getParent());
 Files.createFile(storagePath);
}

代码示例来源:origin: neo4j/neo4j

@Test
void shouldRoundTripFilesWithDifferentContent() throws IOException, IncorrectFormat
{
  Path directory = testDirectory.directory( "a-directory" ).toPath();
  Files.createDirectories( directory );
  Files.write( directory.resolve( "a-file" ), "text".getBytes() );
  Files.write( directory.resolve( "another-file" ), "some-different-text".getBytes() );
  assertRoundTrips( directory );
}

代码示例来源:origin: ctripcorp/apollo

private File findLocalCacheDir() {
 try {
  String defaultCacheDir = m_configUtil.getDefaultLocalCacheDir();
  Path path = Paths.get(defaultCacheDir);
  if (!Files.exists(path)) {
   Files.createDirectories(path);
  }
  if (Files.exists(path) && Files.isWritable(path)) {
   return new File(defaultCacheDir, CONFIG_DIR);
  }
 } catch (Throwable ex) {
  //ignore
 }
 return new File(ClassLoaderUtil.getClassPath(), CONFIG_DIR);
}

代码示例来源:origin: jooby-project/jooby

private void onSyncPackageJson(Config conf, Path workDirectory, Throwing.Consumer<String> action)
  throws IOException {
 Path tmp = Paths.get(conf.getString("application.tmpdir"), "package.json");
 Files.createDirectories(tmp);
 String sha1 = Hashing.sha256()
   .hashBytes(Files.readAllBytes(workDirectory.resolve("package.json")))
   .toString();
 Path lastSha1 = tmp.resolve(sha1);
 if (!Files.exists(lastSha1) || !Files.exists(workDirectory.resolve("node_modules"))) {
  action.accept("install");
  Try.of(Files.walk(tmp))
    .run(files -> files.filter(f -> !f.equals(tmp)).forEach(throwingConsumer(Files::deleteIfExists)));
  Files.write(tmp.resolve(lastSha1), Arrays.asList(""));
 }
}

代码示例来源:origin: SonarSource/sonarqube

private static void mkdir(File dir) {
 try {
  Files.createDirectories(dir.toPath());
 } catch (IOException e) {
  throw new IllegalStateException("Fail to create cache directory: " + dir, e);
 }
}

代码示例来源:origin: neo4j/neo4j

@Test
void shouldMakeFromCanonical() throws IOException, CommandFailed, IncorrectUsage, IncorrectFormat
{
  Path dataDir = testDirectory.directory( "some-other-path" ).toPath();
  Path databaseDir = dataDir.resolve( "databases/foo.db" );
  Files.createDirectories( databaseDir );
  Files.write( configDir.resolve( Config.DEFAULT_CONFIG_FILE_NAME ), singletonList( formatProperty( data_directory, dataDir ) ) );
  new LoadCommand( homeDir, configDir, loader )
      .execute( ArrayUtil.concat( new String[]{"--database=foo.db", "--from=foo.dump"} ) );
  verify( loader ).load( eq( Paths.get( new File( "foo.dump" ).getCanonicalPath() ) ), any(), any() );
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

static void createJar(final URI jarURI, final File workDir, final File f) throws Exception {
  final Map<String, String> env = new HashMap<>(); 
  env.put("create", "true");
  final URI uri = URI.create("jar:file://" + jarURI.getRawPath());
  try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {   
    final Path path = zipfs.getPath(workDir.toPath().relativize(f.toPath()).toString());
    if (path.getParent() != null) {
      Files.createDirectories(path.getParent());
    }
    Files.copy(f.toPath(),
        path, 
        StandardCopyOption.REPLACE_EXISTING ); 
  } 
}

代码示例来源:origin: RipMeApp/ripme

private void saveHistory() {
  Path historyFile = Paths.get(Utils.getConfigDir() + File.separator + "history.json");
  try {
    if (!Files.exists(historyFile)) {
      Files.createDirectories(historyFile.getParent());
      Files.createFile(historyFile);
    }
    HISTORY.toFile(historyFile.toString());
    Utils.setConfigList("download.history", Collections.emptyList());
  } catch (IOException e) {
    LOGGER.error("Failed to save history to file " + historyFile, e);
  }
}

代码示例来源:origin: embulk/embulk

private void copy(String sourceResourcePath, String destinationFileName) throws IOException {
  final Path destinationPath = this.pluginBasePath.resolve(destinationFileName);
  Files.createDirectories(destinationPath.getParent());
  Files.copy(EmbulkNew.class.getClassLoader().getResourceAsStream(sourceResourcePath), destinationPath);
}

代码示例来源:origin: neo4j/neo4j

@Test
void shouldNotDeleteTheOldDatabaseIfForceArgumentIsNotProvided()
    throws CommandFailed, IncorrectUsage, IOException, IncorrectFormat
{
  Path databaseDirectory = homeDir.resolve( "data/databases/foo.db" );
  Files.createDirectories( databaseDirectory );
  doAnswer( ignored ->
  {
    assertThat( Files.exists( databaseDirectory ), equalTo( true ) );
    return null;
  } ).when( loader ).load( any(), any(), any() );
  execute( "foo.db" );
}

代码示例来源:origin: pmd/pmd

@Override
  public void write(Path path, List<String> lines) throws IOException {
    Files.createDirectories(path.getParent());
    Files.write(path, lines, StandardCharsets.UTF_8);
  }
}

代码示例来源:origin: wildfly/wildfly

public AtomicFileOutputStream(final Path path) throws IOException {
  final Path parent = path.getParent();
  if (parent != null && parent.getNameCount() != 0 && ! Files.exists(parent)) {
    Files.createDirectories(parent);
  }
  current = new OpenState(Files.newOutputStream(path.resolveSibling(path.getFileName() + ".new"), CREATE, TRUNCATE_EXISTING), path);
}

代码示例来源:origin: apache/geode

private void ensureExistence(Path directory) throws IOException {
 if (!Files.exists(directory)) {
  Files.createDirectories(directory);
 }
}

代码示例来源:origin: oracle/helidon

private void ensureBeansXml(Path classesDir) throws IOException {
  Path beansPath = classesDir.resolve("META-INF/beans.xml");
  if (Files.exists(beansPath)) {
    return;
  }
  try (InputStream beanXmlTemplate = HelidonDeployableContainer.class.getResourceAsStream("/templates/beans.xml")) {
    Path metaInfPath = beansPath.getParent();
    if (null != metaInfPath) {
      Files.createDirectories(metaInfPath);
    }
    if (null == beanXmlTemplate) {
      Files.write(beansPath, new byte[0]);
    } else {
      Files.copy(beanXmlTemplate, beansPath);
    }
  }
}

代码示例来源:origin: traccar/traccar

private File createFile(String uniqueId, String name) throws IOException {
  Path filePath = Paths.get(path, uniqueId, name);
  Path directoryPath = filePath.getParent();
  if (directoryPath != null) {
    Files.createDirectories(directoryPath);
  }
  return filePath.toFile();
}

代码示例来源:origin: neo4j/neo4j

@Test
void shouldRoundTripFilesInDirectories() throws IOException, IncorrectFormat
{
  Path directory = testDirectory.directory( "a-directory" ).toPath();
  Path subdir = directory.resolve( "a-subdirectory" );
  Files.createDirectories( subdir );
  Files.write( subdir.resolve( "a-file" ), "text".getBytes() );
  assertRoundTrips( directory );
}

相关文章

微信公众号

最新文章

更多