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

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

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

Path.toAbsolutePath介绍

暂无

代码示例

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

CannotWriteException( Path file )
  {
    super( format( "Could not write to: %s", file.toAbsolutePath().toString() ) );
  }
}

代码示例来源:origin: perwendel/spark

private static String unixifyPath(String path) {
  return Paths.get(path).toAbsolutePath().toString().replace("\\", "/");
}

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

public DirectoryLock(Path directory) {
 this.lockFilePath = directory.resolve(LOCK_FILE_NAME).toAbsolutePath();
}

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

/**
 * Creates the storage directory path, including any necessary but nonexistent parent directories.
 * If the directory already exists, do nothing.
 *
 * Also, appropriate directory permissions (w/ StickyBit) are set.
 *
 * @param path storage directory path to create
 * @param workerDataFolderPermissions the permissions to set for the worker's data folder
 * @return true if the directory is created and false if the directory already exists
 */
public static boolean createStorageDirPath(String path, String workerDataFolderPermissions)
  throws IOException {
 if (Files.exists(Paths.get(path))) {
  return false;
 }
 Path storagePath;
 try {
  storagePath = Files.createDirectories(Paths.get(path));
 } catch (UnsupportedOperationException | SecurityException | IOException e) {
  throw new IOException("Failed to create folder " + path, e);
 }
 String absolutePath = storagePath.toAbsolutePath().toString();
 changeLocalFilePermission(absolutePath, workerDataFolderPermissions);
 setLocalDirStickyBit(absolutePath);
 return true;
}

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

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

代码示例来源:origin: spotify/helios

private PersistentAtomicReference(final Path filename,
                 final JavaType javaType,
                 final Supplier<? extends T> initialValue)
  throws IOException, InterruptedException {
 try {
  this.filename = filename.toAbsolutePath();
  this.tempfilename = filename.getFileSystem().getPath(this.filename.toString() + ".tmp");
  if (Files.exists(filename)) {
   final byte[] bytes = Files.readAllBytes(filename);
   if (bytes.length > 0) {
    value = Json.read(bytes, javaType);
   } else {
    value = initialValue.get();
   }
  } else {
   value = initialValue.get();
  }
 } catch (InterruptedIOException | ClosedByInterruptException e) {
  throw new InterruptedException(e.getMessage());
 }
}

代码示例来源:origin: Netflix/genie

DownloadCommandArguments(
  final ArgumentDelegates.CacheArguments cacheArguments
) {
  this.cacheArguments = cacheArguments;
  this.fileUris = Lists.newArrayList();
  this.destinationDirectory = Paths.get("").toAbsolutePath().toFile();
}

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

public static String createTempDir(String name) {
  Path tmpDir;
  try {
    tmpDir = Files.createTempDirectory(name);
  } catch (IOException e) {
    throw new RuntimeException("Couldn't create temporary directory!", e);
  }
  String tmpPath = tmpDir.toAbsolutePath().toString();
  tmpDir.toFile().deleteOnExit();
  return tmpPath;
}

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

private Path findSonarHome(ScannerProperties props) {
 String home = props.property("sonar.userHome");
 if (home != null) {
  return Paths.get(home).toAbsolutePath();
 }
 home = system.envVariable("SONAR_USER_HOME");
 if (home != null) {
  return Paths.get(home).toAbsolutePath();
 }
 home = system.property("user.home");
 return Paths.get(home, ".sonar").toAbsolutePath();
}

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

private Path buildEmbulkHome() {
  final String userHomeProperty = System.getProperty("user.home");
  if (userHomeProperty == null) {
    throw new RuntimeException("User home directory is not set in Java properties.");
  }
  final Path userHome;
  try {
    userHome = Paths.get(userHomeProperty);
  } catch (InvalidPathException ex) {
    throw new RuntimeException("User home directory is invalid: \"" + userHomeProperty + "\"", ex);
  }
  return userHome.toAbsolutePath().resolve(".embulk");
}

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

@Nonnull
public AnalysisRunner addAuxClasspathEntry(Path path) {
  Objects.requireNonNull(path);
  if (!path.toFile().canRead()) {
    throw new IllegalArgumentException("Cannot read " + path.toAbsolutePath());
  }
  auxClasspathEntries.add(path);
  return this;
}

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

private JwkKeys loadJwkKeysFromLocation(String uri) {
  Path path;
  try {
    path = Paths.get(uri);
  } catch (InvalidPathException e) {
    path = null;
  }
  if (path != null && Files.exists(path)) {
    try {
      return loadJwkKeys(new String(Files.readAllBytes(path), UTF_8));
    } catch (IOException e) {
      throw new SecurityException("Failed to load public key(s) from path: " + path.toAbsolutePath(), e);
    }
  } else {
    try (InputStream is = locateStream(uri)) {
      return getPublicKeyFromContent(is);
    } catch (IOException e) {
      throw new SecurityException("Failed to load public key(s) from : " + uri, e);
    }
  }
}

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

private void processFileError(InputFile inputFile, SensorContext context) {
 Path ioFile = inputFile.file().toPath();
 Path errorFile = ioFile.resolveSibling(ioFile.getFileName() + ERROR_EXTENSION).toAbsolutePath();
 if (Files.exists(errorFile) && Files.isRegularFile(errorFile)) {
  LOG.debug("Processing " + errorFile.toString());
  try {
   List<String> lines = Files.readAllLines(errorFile, context.fileSystem().encoding());
   for (String line : lines) {
    if (StringUtils.isBlank(line) || line.startsWith("#")) {
     continue;
    }
    processLine(line, inputFile, context);
   }
  } catch (IOException e) {
   throw new IllegalStateException(e);
  }
 }
}

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

private Path relative(final List<Object[]> paths, final Path path) {
 for (Object[] meta : paths) {
  Path root = ((Path) meta[0]).toAbsolutePath();
  Path relative = root.relativize(path);
  if (Files.exists(root.resolve(relative))) {
   return relative;
  }
 }
 return path;
}

代码示例来源:origin: line/armeria

FileSystemHttpVfs(Path rootDir) {
  this.rootDir = requireNonNull(rootDir, "rootDir").toAbsolutePath();
  if (!Files.exists(this.rootDir) || !Files.isDirectory(this.rootDir)) {
    throw new IllegalArgumentException("rootDir: " + rootDir + " (not a directory");
  }
}

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

private String buildGemfilePath(final String bundleDirectoryString) throws ProvisionException {
  final Path bundleDirectory;
  try {
    bundleDirectory = Paths.get(bundleDirectoryString);
  } catch (InvalidPathException ex) {
    throw new ProvisionException("Bundle directory is invalid: \"" + bundleDirectoryString + "\"", ex);
  }
  return bundleDirectory.toAbsolutePath().resolve("Gemfile").toString();
}

代码示例来源:origin: guoguibing/librec

/**
 * @return the path to current folder
 */
public static String getCurrentPath() {
  return Paths.get("").toAbsolutePath().toString();
}

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

/**
 * Formats the worker data folder.
 *
 * @param folder folder path
 */
private static void formatWorkerDataFolder(String folder) throws IOException {
 Path path = Paths.get(folder);
 if (Files.exists(path)) {
  FileUtils.deletePathRecursively(folder);
 }
 Files.createDirectory(path);
 // For short-circuit read/write to work, others needs to be able to access this directory.
 // Therefore, default is 777 but if the user specifies the permissions, respect those instead.
 String permissions = ServerConfiguration.get(PropertyKey.WORKER_DATA_FOLDER_PERMISSIONS);
 Set<PosixFilePermission> perms = PosixFilePermissions.fromString(permissions);
 Files.setPosixFilePermissions(path, perms);
 FileUtils.setLocalDirStickyBit(path.toAbsolutePath().toString());
}

相关文章