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

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

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

Path.getFileName介绍

暂无

代码示例

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: spring-projects/spring-framework

/**
 * This implementation returns the name of the file.
 * @see java.nio.file.Path#getFileName()
 */
@Override
public String getFilename() {
  return this.path.getFileName().toString();
}

代码示例来源: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: apache/incubator-druid

@Override
 public boolean apply(@Nullable URL input)
 {
  try {
   if (input == null) {
    return false;
   }
   final String fName = Paths.get(input.toURI()).getFileName().toString();
   return fName.startsWith("druid") && fName.endsWith(".jar") && !fName.endsWith("selfcontained.jar");
  }
  catch (URISyntaxException e) {
   throw Throwables.propagate(e);
  }
 }
};

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

@Override
public File[] listFiles( File directory, final FilenameFilter filter )
{
  try ( Stream<Path> listing = Files.list( path( directory ) ) )
  {
    return listing
        .filter( entry -> filter.accept( entry.getParent().toFile(), entry.getFileName().toString() ) )
        .map( Path::toFile )
        .toArray( File[]::new );
  }
  catch ( IOException e )
  {
    return null;
  }
}

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

private void removeAll(String baseName) throws IOException {
  try (DirectoryStream<Path> children = fsOps.newDirectoryStream(topologyBasicBlobsRootDir)) {
    for (Path p : children) {
      String fileName = p.getFileName().toString();
      if (fileName.startsWith(baseName)) {
        fsOps.deleteIfExists(p.toFile());
      }
    }
  }
}

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

static Collection<String> getLocalizedUsers(Path localBaseDir) throws IOException {
  Path userCacheDir = getUserCacheDir(localBaseDir);
  if (!Files.exists(userCacheDir)) {
    return Collections.emptyList();
  }
  return Files.list(userCacheDir).map((p) -> p.getFileName().toString()).collect(Collectors.toList());
}

代码示例来源:origin: ata4/disunity

outputDir = file.getParent();
  if (outputDir == null) {
    outputDir = Paths.get(".");
  .forEach(uncheck(entry -> {
    progress.update(Optional.of(entry.name()), done.getAndIncrement() / (double) total);
    Path entryFile = outputDir.resolve(entry.name());
    Files.createDirectories(entryFile.getParent());
    Files.copy(entry.inputStream(), entryFile, REPLACE_EXISTING);
String bundleName = outputDir.getFileName().toString();
Path propsFile = outputDir.getParent().resolve(bundleName + ".json");
BundleProps.write(propsFile, bundle);

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

protected static String calculateDefaultOutputDirectory(Path currentPath) {
  Path currentAbsolutePath = currentPath.toAbsolutePath();
  Path parent = currentAbsolutePath.getParent();
  if (currentAbsolutePath.getRoot().equals(parent)) {
    return parent.toString();
  } else {
    Path currentNormalizedPath = currentAbsolutePath.normalize();
    return "../" + currentNormalizedPath.getFileName().toString();
  }
}

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

/**
 * @param response Http response.
 * @param type Type.
 * @param path Path to file.
 * @throws IOException If failed.
 */
private static void handleRequest(HttpServletResponse response, String type, String path) throws IOException {
  Path path0 = Paths.get(path);
  response.setContentType(type);
  response.setHeader("Content-Disposition", "attachment; filename=\"" + path0.getFileName() + "\"");
  try (HttpOutput out = (HttpOutput)response.getOutputStream()) {
    out.sendContent(FileChannel.open(path0, StandardOpenOption.READ));
  }
}

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

private void backupDeployedJars(Map<Path, Path> jarFiles, RestoreScript restoreScript)
  throws IOException {
 Path jarsDirectory = backupDirectory.resolve(DEPLOYED_JARS_DIRECTORY);
 Files.createDirectories(jarsDirectory);
 for (Map.Entry<Path, Path> jarFileEntry : jarFiles.entrySet()) {
  Path jarFile = jarFileEntry.getKey();
  Path originalFile = jarFileEntry.getValue();
  Path destination = jarsDirectory.resolve(jarFile.getFileName());
  moveFileOrDirectory(jarFile, destination);
  restoreScript.addFile(originalFile.toFile(), destination.toFile());
 }
}

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

private void moveFilesOrDirectories(Collection<Path> paths, Path targetDirectory)
  throws IOException {
 for (Path userFile : paths) {
  Path destination = targetDirectory.resolve(userFile.getFileName());
  moveFileOrDirectory(userFile, destination);
 }
}

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

@Override
public FileVisitResult visitFile(Path filePath, BasicFileAttributes attrs) throws IOException {
 File file = filePath.toFile();
 if (file.isDirectory()) {
  deleteDirectory(file);
 } else if (filePath.getFileName().equals(SHAREDMEMORY_FILE)) {
  return CONTINUE;
 } else if (!symLink || !filePath.equals(path)) {
  Files.delete(filePath);
 }
 return CONTINUE;
}

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

private void ensureDirectoryExists(Path filePath) {
  try {
    Files.createDirectories(filePath.getParent());
  } catch (Exception e) {
    throw new RuntimeException("Cannot create directory for flexibleConfig " + filePath.getFileName() + "!");
  }
}

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

private Path tempPath() {
  Path parent = path.getParent();
  File file = parent.toFile();
  if (!file.exists()) {
    file.mkdirs();
  }
  return parent.resolve(path.getFileName().toString() + '.' + tempSuffix());
}

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

/**
 * @return the name of current folder
 */
public static String getCurrentFolder() {
  return Paths.get("").toAbsolutePath().getFileName().toString();
}

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

public void copyOptJarsToLib(String jarNamePrefix) throws FileNotFoundException, IOException {
  final Optional<Path> reporterJarOptional;
  try (Stream<Path> logFiles = Files.walk(opt)) {
    reporterJarOptional = logFiles
      .filter(path -> path.getFileName().toString().startsWith(jarNamePrefix))
      .findFirst();
  }
  if (reporterJarOptional.isPresent()) {
    final Path optReporterJar = reporterJarOptional.get();
    final Path libReporterJar = lib.resolve(optReporterJar.getFileName());
    Files.copy(optReporterJar, libReporterJar);
    filesToDelete.add(new AutoClosablePath(libReporterJar));
  } else {
    throw new FileNotFoundException("No jar could be found matching the pattern " + jarNamePrefix + ".");
  }
}

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

@Override
 public FileVisitResult visitFile(Path candidate, BasicFileAttributes attrs)
   throws IOException {
  String fileName = candidate.getFileName().toString();
  if (!fileName.endsWith(completedSuffix) &&
    !isFileInTrackerDir(trackerDirCompletedFiles, candidate) &&
    !fileName.startsWith(".") &&
    includePattern.matcher(fileName).matches() &&
    !ignorePattern.matcher(fileName).matches()) {
   candidateFiles.add(candidate.toFile());
  }
  return FileVisitResult.CONTINUE;
 }
});

相关文章