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

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

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

Files.notExists介绍

暂无

代码示例

代码示例来源:origin: org.assertj/assertj-core

public boolean notExists(Path path, LinkOption... options) {
 return Files.notExists(path, options);
}

代码示例来源:origin: joel-costigliola/assertj-core

public boolean notExists(Path path, LinkOption... options) {
 return Files.notExists(path, options);
}

代码示例来源:origin: shopizer-ecommerce/shopizer

private void createDirectoryIfNorExist(Path path) throws IOException {
 if (Files.notExists(path)) {
  Files.createDirectory(path);
 }
}

代码示例来源:origin: shopizer-ecommerce/shopizer

private void createDirectoryIfNorExist(Path path) throws IOException {
 if (Files.notExists(path)) {
  Files.createDirectory(path);
 }
}

代码示例来源:origin: allure-framework/allure2

private boolean isValidResultsDirectory(final Path resultsDirectory) {
    if (Files.notExists(resultsDirectory)) {
      LOGGER.warn("{} does not exists", resultsDirectory);
      return false;
    }
    if (!Files.isDirectory(resultsDirectory)) {
      LOGGER.warn("{} is not a directory", resultsDirectory);
      return false;
    }
    return true;
  }
}

代码示例来源:origin: square/javapoet

/** Writes this to {@code directory} as UTF-8 using the standard directory structure. */
public void writeTo(Path directory) throws IOException {
 checkArgument(Files.notExists(directory) || Files.isDirectory(directory),
   "path %s exists but is not a directory.", directory);
 Path outputDirectory = directory;
 if (!packageName.isEmpty()) {
  for (String packageComponent : packageName.split("\\.")) {
   outputDirectory = outputDirectory.resolve(packageComponent);
  }
  Files.createDirectories(outputDirectory);
 }
 Path outputPath = outputDirectory.resolve(typeSpec.name + ".java");
 try (Writer writer = new OutputStreamWriter(Files.newOutputStream(outputPath), UTF_8)) {
  writeTo(writer);
 }
}

代码示例来源:origin: networknt/light-4j

@Override
  public FileVisitResult preVisitDirectory(Path dir,
                       BasicFileAttributes attrs) throws IOException {
    final Path dirToCreate = zipFileSystem.getPath(root.toString(),
        dir.toString());
    if(Files.notExists(dirToCreate)){
      if(logger.isDebugEnabled()) logger.debug("Creating directory %s\n", dirToCreate);
      Files.createDirectories(dirToCreate);
    }
    return FileVisitResult.CONTINUE;
  }
});

代码示例来源:origin: networknt/light-4j

@Override
  public FileVisitResult preVisitDirectory(Path dir,
                       BasicFileAttributes attrs) throws IOException {
    final Path dirToCreate = Paths.get(destDir.toString(),
        dir.toString());
    if(Files.notExists(dirToCreate)){
      if(logger.isDebugEnabled()) logger.debug("Creating directory %s", dirToCreate);
      Files.createDirectory(dirToCreate);
    }
    return FileVisitResult.CONTINUE;
  }
});

代码示例来源:origin: bwssytems/ha-bridge

private String repositoryReader(Path filePath) {
  String content = null;
  if(Files.notExists(filePath) || !Files.isReadable(filePath)){
    log.warn("Error reading the file: " + filePath + " - Does not exist or is not readable. continuing...");
    return null;
  }
  
  try {
    content = new String(Files.readAllBytes(filePath));
  } catch (IOException e) {
    log.error("Error reading the file: " + filePath + " message: " + e.getMessage(), e);
  }
  
  return content;
}

代码示例来源:origin: bwssytems/ha-bridge

private String configReader(Path filePath) {
  String content = null;
  if(Files.notExists(filePath) || !Files.isReadable(filePath)){
    log.warn("Error reading the file: " + filePath + " - Does not exist or is not readable. continuing...");
    return null;
  }
  try {
    content = new String(Files.readAllBytes(filePath));
  } catch (IOException e) {
    log.error("Error reading the file: " + filePath + " message: " + e.getMessage(), e);
  }
  
  return content;
}

代码示例来源:origin: allure-framework/allure2

@Override
  public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
    if (Files.notExists(file)) {
      return FileVisitResult.CONTINUE;
    }
    final Path dest = outputDirectory.resolve(sourceDirectory.relativize(file));
    try {
      Files.copy(file, dest, StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
      LOGGER.error("Could not copy file", e);
    }
    return FileVisitResult.CONTINUE;
  }
}

代码示例来源:origin: bwssytems/ha-bridge

private String repositoryReader(Path filePath) {

    String content = null;
    if(Files.notExists(filePath) || !Files.isReadable(filePath)){
      log.warn("Error reading the file: " + filePath + " - Does not exist or is not readable. continuing...");
      return null;
    }

    
    try {
      content = new String(Files.readAllBytes(filePath));
    } catch (IOException e) {
      log.error("Error reading the file: " + filePath + " message: " + e.getMessage(), e);
    }
    
    return content;
  }
}

代码示例来源:origin: confluentinc/ksql

public static boolean createFile(final Path path) {
 try {
  final Path parent = path.getParent();
  if (parent == null) {
   log.warn("Failed to create file as the parent was null. path: {}", path);
   return false;
  }
  Files.createDirectories(parent);
  if (Files.notExists(path)) {
   Files.createFile(path);
  }
  return true;
 } catch (final Exception e) {
  log.warn("createFile failed, path: {}", path, e);
  return false;
 }
}

代码示例来源:origin: siacs/Conversations

@Override
public final byte[] put(String key, byte[] value) {
  // Make sure the directory exists.
  byte[] data = get(key);
  if (!Arrays.equals(data, value))
    try {
      if (Files.notExists(cacheDirectory)) {
        Files.createDirectories(cacheDirectory);
      }
      Path file = cacheDirectory.resolve(key);
      Files.write(file, value);
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  return data;
}

代码示例来源:origin: allure-framework/allure2

private Optional<PluginConfiguration> loadPluginConfiguration(final Path pluginDirectory) {
  final Path configuration = pluginDirectory.resolve("allure-plugin.yml");
  if (Files.notExists(configuration)) {
    LOGGER.warn("Invalid plugin directory " + pluginDirectory);
    return Optional.empty();
  }
  final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
  try (InputStream is = Files.newInputStream(configuration)) {
    return Optional.of(mapper.readValue(is, PluginConfiguration.class));
  } catch (IOException e) {
    LOGGER.error("Could not read plugin configuration: {}", e);
    return Optional.empty();
  }
}

代码示例来源:origin: lets-blade/blade

/**
 * Get banner text
 *
 * @return return blade start banner text
 */
public String bannerText() {
  if (null != bannerText) return bannerText;
  String bannerPath = environment.get(ENV_KEY_BANNER_PATH, null);
  if (StringKit.isEmpty(bannerPath) || Files.notExists(Paths.get(bannerPath))) {
    return null;
  }
  try {
    BufferedReader bufferedReader = Files.newBufferedReader(Paths.get(bannerPath));
    bannerText = bufferedReader.lines().collect(Collectors.joining("\r\n"));
  } catch (Exception e) {
    log.error("Load Start Banner file error", e);
  }
  return bannerText;
}

代码示例来源:origin: lets-blade/blade

/**
 * Get banner text
 *
 * @return return blade start banner text
 */
public String bannerText() {
  if (null != bannerText) return bannerText;
  String bannerPath = environment.get(ENV_KEY_BANNER_PATH, null);
  if (StringKit.isEmpty(bannerPath) || Files.notExists(Paths.get(bannerPath))) {
    return null;
  }
  try {
    BufferedReader bufferedReader = Files.newBufferedReader(Paths.get(bannerPath));
    bannerText = bufferedReader.lines().collect(Collectors.joining("\r\n"));
  } catch (Exception e) {
    log.error("Load Start Banner file error", e);
  }
  return bannerText;
}

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

private void addConfigFileToBackup(URL fileUrl) throws IOException {
 if (fileUrl == null) {
  return;
 }
 try {
  Path source = getSource(fileUrl);
  if (Files.notExists(source)) {
   return;
  }
  Path destination = configDirectory.resolve(source.getFileName());
  Files.copy(source, destination, StandardCopyOption.COPY_ATTRIBUTES);
  backupDefinition.addConfigFileToBackup(destination);
 } catch (URISyntaxException e) {
  throw new IOException(e);
 }
}

代码示例来源:origin: Swagger2Markup/swagger2markup

/**
 * Creates a Swagger2MarkupConverter.Builder using a local Path.
 *
 * @param swaggerPath the local Path
 * @return a Swagger2MarkupConverter
 */
public static Builder from(Path swaggerPath) {
  Validate.notNull(swaggerPath, "swaggerPath must not be null");
  if (Files.notExists(swaggerPath)) {
    throw new IllegalArgumentException(String.format("swaggerPath does not exist: %s", swaggerPath));
  }
  try {
    if (Files.isHidden(swaggerPath)) {
      throw new IllegalArgumentException("swaggerPath must not be a hidden file");
    }
  } catch (IOException e) {
    throw new RuntimeException("Failed to check if swaggerPath is a hidden file", e);
  }
  return new Builder(swaggerPath);
}

代码示例来源:origin: cbeust/testng

@Test
public void shouldHonorSuiteName() throws IOException {
 Path outputDirectory = TestHelper.createRandomDirectory();
 TestNG tng = create(outputDirectory, SampleA.class, SampleB.class);
 tng.addListener(new TestHTMLReporter());
 Path fileA = outputDirectory.resolve("SuiteA-JDK5");
 Path fileB = outputDirectory.resolve("SuiteB-JDK5");
 Assert.assertTrue(Files.notExists(fileA));
 Assert.assertTrue(Files.notExists(fileB));
 tng.run();
 Assert.assertTrue(Files.exists(fileA));
 Assert.assertTrue(Files.exists(fileB));
}

相关文章

微信公众号

最新文章

更多