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

x33g5p2x  于2022-01-25 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(141)

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

Path.resolve介绍

暂无

代码示例

canonical example by Tabnine

public void pathUsage() {
  Path currentDir = Paths.get("."); // currentDir = "."
  Path fullPath = currentDir.toAbsolutePath(); // fullPath = "/Users/guest/workspace"
  Path one = currentDir.resolve("file.txt"); // one = "./file.txt"
  Path fileName = one.getFileName(); // fileName = "file.txt"
}

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

private static Path rotationalPathFor( Path deviceName )
{
  return Paths.get( "/sys/block" ).resolve( deviceName ).resolve( "queue" ).resolve( "rotational" );
}

代码示例来源: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: pxb1988/dex2jar

@Override
  public void visitFile(Path file, String relative) throws IOException {
    if (file.getFileName().toString().endsWith(".class")) {
      Files.copy(file, outRoot.resolve(relative));
    }
  }
});

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

protected static File resolvePath(File baseDir, String path) {
 Path filePath = Paths.get(path);
 if (!filePath.isAbsolute()) {
  filePath = baseDir.toPath().resolve(path);
 }
 return filePath.normalize().toFile();
}

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

/**
 * Copy file to working directory.
 *
 * @param filePath File path.
 * @return File name.
 * @throws IOException If coping failed.
 */
String copyToWorkDir(String filePath) throws IOException {
  Path srcFile = Paths.get(filePath);
  if (Files.exists(srcFile)) {
    checkDownloadFolder();
    Path newDir = Paths.get(downloadFolder);
    Path fileName = srcFile.getFileName();
    Files.copy(srcFile, newDir.resolve(fileName), StandardCopyOption.REPLACE_EXISTING);
    return fileName.toString();
  }
  return null;
}

代码示例来源:origin: libgdx/packr

@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
  Path relative = sourcePath.relativize(dir);
  Path target = targetPath.resolve(relative);
  File folder = target.toFile();
  if (!folder.exists()) {
    mkdirs(folder);
  }
  return FileVisitResult.CONTINUE;
}

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

@Override public File resolve(final CacheDescriptor item) {
  String version = item.getVersion()
    .replace("^", "")
    .replace("v", "");

  String classifier = Optional.ofNullable(item.getClassifier())
    .map(it -> "-" + it)
    .orElse("");
  Path artifactId = Paths.get(item.getName()).resolve(version)
    .resolve(item.getName() + "-" + version + classifier + "." + item.getExtension());
  return repository.resolve(groupId).resolve(artifactId).toAbsolutePath().toFile();
 }
}

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

static String resolveLocalRepoPath(String localRepoPath) {
 // todo decouple home folder resolution
 // find homedir
 String home = System.getenv("ZEPPELIN_HOME");
 if (home == null) {
  home = System.getProperty("zeppelin.home");
 }
 if (home == null) {
  home = "..";
 }
 return Paths.get(home).resolve(localRepoPath).toAbsolutePath().toString();
}

代码示例来源:origin: btraceio/btrace

private static void addPreconfLibs(String libs) {
  URL u = Main.class.getClassLoader().getResource(Main.class.getName().replace('.', '/') + ".class");
  if (u != null) {
    String path = u.toString();
    int delimiterPos = path.lastIndexOf('!');
    if (delimiterPos > -1) {
      String jar = path.substring(9, delimiterPos);
      File jarFile = new File(jar);
      Path libRoot = new File(jarFile.getParent() + File.separator + "btrace-libs").toPath();
      Path libFolder = libs != null ? libRoot.resolve(libs) : libRoot;
      if (Files.exists(libFolder)) {
        appendToBootClassPath(libFolder);
        appendToSysClassPath(libFolder);
      } else if (libs != null) {
        // for user provided libs config report error if the location does not exist
        DebugSupport.warning("Invalid 'libs' configuration [" + libs + "]. " +
               "Path '" + libFolder.toAbsolutePath().toString() + "' does not exist.");
      }
    }
  }
}

代码示例来源:origin: real-logic/aeron

@Test
public void shouldNotThrowWhenOldRecordingLogsAreDeleted() throws IOException
{
  createSegmentFile(recordingThreeId);
  final Path segmentFilePath = Paths.get(segmentFileName(recordingThreeId, 0));
  final boolean segmentFileExists = Files.exists(archiveDir.toPath().resolve(segmentFilePath));
  assumeThat(segmentFileExists, is(true));
  final Catalog catalog = new Catalog(archiveDir, null, 0, MAX_ENTRIES, clock);
  catalog.close();
}

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

@Test
  public void shouldRemoveDirectory() throws Exception {
    Path path = Paths.get(Testing.Files.dataDir(), "test-dir");
    assertThat(path.toFile().mkdirs()).isTrue();

    Path file = path.resolve("file.txt");
    assertThat(file.toFile().createNewFile()).isTrue();

    Testing.Files.delete(path);
    assertThat(java.nio.file.Files.exists(path)).isFalse();
  }
}

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

throws IOException, KeyNotFoundException, AuthorizationException {
synchronized (LocallyCachedTopologyBlob.class) {
  if (!Files.exists(topologyBasicBlobsRootDir)) {
    Files.createDirectories(topologyBasicBlobsRootDir);
    fsOps.setupStormCodeDir(owner, topologyBasicBlobsRootDir.toFile());
  String resourcesJar = resourcesJar();
  URL url = classloader.getResource(ServerConfigUtils.RESOURCES_SUBDIR);
  Path extractionDest = topologyBasicBlobsRootDir.resolve(type.getTempExtractionDir(LOCAL_MODE_JAR_VERSION));
  if (resourcesJar != null) {
    LOG.info("Extracting resources from jar at {} to {}", resourcesJar, extractionDest);
      extractDirFromJar(urlConnection.getJarFileURL().getFile(), ServerConfigUtils.RESOURCES_SUBDIR, extractionDest);
    } else {
      fsOps.copyDirectory(new File(url.getFile()), extractionDest.toFile());
    Path path = topologyBasicBlobsRootDir.resolve(type.getTempFileName(v));
    fsOps.forceMkdir(path.getParent());
    return path;
  Path extractionDest = topologyBasicBlobsRootDir.resolve(type.getTempExtractionDir(downloadMeta.getVersion()));
  extractDirFromJar(tmpLocation.toAbsolutePath().toString(), ServerConfigUtils.RESOURCES_SUBDIR,
           extractionDest);

代码示例来源: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: pxb1988/dex2jar

@Override
  public void visitFile(Path file, String relative) throws IOException {
    Path out = outRoot.resolve(relative);
    if (Files.exists(out)) {
      System.err.println("skip " + relative + " in " + stub);
    } else {
      createParentDirectories(out);
      Files.copy(file, out);
    }
  }
});

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

public static String getRelativePath( File folder, Setting<File> setting )
{
  return folder.toPath().resolve( setting.getDefaultValue() ).toString();
}

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

public void stopFlinkCluster() throws IOException {
  AutoClosableProcess.runBlocking("Stop Flink Cluster", bin.resolve("stop-cluster.sh").toAbsolutePath().toString());
}

代码示例来源:origin: springside/springside4

@Test
public void testMakesureDirExists() throws Exception {
  Path dir = FileUtil.createTempDir();
  String child1 = "child1";
  Path child1Dir = dir.resolve(child1);
  FileUtil.makesureDirExists(child1Dir.toString());
  assertThat(child1Dir).exists();
  String child2 = "child2";
  Path child2Dir = dir.resolve(child2);
  FileUtil.makesureDirExists(child2Dir);
  assertThat(child2Dir).exists();
  String child3 = "child3";
  Path child3Dir = dir.resolve(child3);
  FileUtil.makesureDirExists(child3Dir.toFile());
  assertThat(child3Dir).exists();
}

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

@Override
  public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    Files.move(file, haStorageDir.toPath().resolve(file.getFileName()));
    return FileVisitResult.CONTINUE;
  }
});

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

private void readVersion() throws IOException {
  Path versionFile = topologyBasicBlobsRootDir.resolve(type.getVersionFileName());
  if (!fsOps.fileExists(versionFile)) {
    version = NOT_DOWNLOADED_VERSION;
  } else {
    String ver = FileUtils.readFileToString(versionFile.toFile(), "UTF8").trim();
    version = Long.parseLong(ver);
  }
}

相关文章