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

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

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

Path.forEach介绍

暂无

代码示例

代码示例来源:origin: net.anwiba.commons/anwiba-commons-core

@SuppressWarnings("nls")
static String resolveSpecialPathNames(final String name) throws IOException {
 final Path normalize = new File(name).toPath().normalize();
 final List<Path> items = new ArrayList<>();
 normalize.forEach(p -> Optional.of(p).filter(i -> !i.equals(Paths.get(".."))).ifPresent(i -> items.add(i)));
 if (items.size() != normalize.getNameCount()) {
  throw new IOException("Entry is outside of the target folder '" + name + "'");
 }
 return items.stream().map(p -> p.toString()).reduce(null, (i, s) -> i == null ? s : i + File.separator + s);
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-utilities

@SuppressWarnings("nls")
static String resolveSpecialPathNames(final String name) throws IOException {
 final Path normalize = new File(name).toPath().normalize();
 final List<Path> items = new ArrayList<>();
 normalize.forEach(p -> Optional.of(p).filter(i -> !i.equals(Paths.get(".."))).ifPresent(i -> items.add(i)));
 if (items.size() != normalize.getNameCount()) {
  throw new IOException("Entry is outside of the target folder '" + name + "'");
 }
 return items.stream().map(p -> p.toString()).reduce(null, (i, s) -> i == null ? s : i + File.separator + s);
}

代码示例来源:origin: IanDarwin/javasrc

public static void main(String[] args) throws Exception {
    // BEGIN main
    Path p = Paths.get("my_junk_file");                    // <1>
    boolean deleted = Files.deleteIfExists(p);             // <2>
    InputStream is =                                       // <3>
        PathsFilesDemo.class.getResourceAsStream("/demo.txt");
    long newFileSize = Files.copy(is, p);                  // <4>
    System.out.println(newFileSize);                       // <5>
    final Path realPath = p.toRealPath();                  // <6>
    System.out.println(realPath);
    realPath.forEach(pc-> System.out.println(pc));         // <7>
    Files.delete(p);                                       // <8>
    // END main
  }
}

代码示例来源:origin: future-architect/uroborosql

/**
 * classファイルから対象パッケージ以下のEnumクラスを取得
 *
 * @param packageName ルートパッケージ名
 * @param dir 対象ディレクトリ
 * @return クラスリスト
 * @throws ClassNotFoundException エラー
 * @throws IOException
 */
private static Set<Class<?>> findEnumClassesWithFile(final String packageName, final Path dir) {
  Set<Class<?>> classes = new HashSet<>();
  try (Stream<Path> stream = Files.walk(dir)) {
    stream.filter(entry -> entry.getFileName().toString().endsWith(".class")).forEach(file -> {
      StringJoiner joiner = new StringJoiner(".", packageName + ".", "");
      dir.relativize(file).forEach(p -> joiner.add(p.toString()));
      String className = joiner.toString().replaceAll(".class$", "");
      loadEnum(className).ifPresent(classes::add);
    });
  } catch (IOException e) {
    LOG.error(e.getMessage(), e);
  }
  return classes;
}

代码示例来源:origin: org.ballerinalang/ballerina-lang

@Override
  public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
    if (Files.isHidden(dir)) {
      return FileVisitResult.SKIP_SUBTREE;
    }
    List<Name> nameComps = new ArrayList<>();
    if (Files.list(dir).filter(f -> isBALFile(f)).count() > 0) {
      int dirNameCount = dir.getNameCount();
      if (dirNameCount > baseNameCount) {
        dir.subpath(baseNameCount, dirNameCount).forEach(
            f -> nameComps.add(new Name(sanitize(f.getFileName().toString(), separator))));
        result.add(new PackageID(Names.ANON_ORG, nameComps, Names.DEFAULT_VERSION));
      }
    }
    if ((dir.getNameCount() + 1) - baseNameCount > maxDepth) {
      return FileVisitResult.SKIP_SUBTREE;
    }
    return FileVisitResult.CONTINUE;
  }
});

相关文章