本文整理了Java中java.nio.file.Files.exists()
方法的一些代码示例,展示了Files.exists()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.exists()
方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:exists
暂无
代码示例来源:origin: springside/springside4
public static boolean isDirExists(Path dirPath) {
return dirPath != null && Files.exists(dirPath) && Files.isDirectory(dirPath);
}
代码示例来源:origin: apache/incubator-druid
@JsonCreator
public LocalLoadSpec(
@JacksonInject LocalDataSegmentPuller puller,
@JsonProperty(value = "path", required = true) final String path
)
{
Preconditions.checkNotNull(path);
this.path = Paths.get(path);
Preconditions.checkArgument(Files.exists(Paths.get(path)), "[%s] does not exist", path);
this.puller = puller;
}
代码示例来源:origin: apache/ignite
/**
* Get Ignite Hadoop config directory.
*
* @param igniteHome Ignite home.
* @return Ignite Hadoop config directory.
*/
private static File igniteHadoopConfig(String igniteHome) {
Path path = Paths.get(igniteHome, "modules", "hadoop", "config");
if (!Files.exists(path))
path = Paths.get(igniteHome, "config", "hadoop");
if (Files.exists(path))
return path.toFile();
else
return new File(igniteHome, "docs");
}
代码示例来源:origin: apache/storm
private void forEachTopologyDistDir(ConsumePathAndId consumer) throws IOException {
Path stormCodeRoot = Paths.get(ConfigUtils.supervisorStormDistRoot(conf));
if (Files.exists(stormCodeRoot) && Files.isDirectory(stormCodeRoot)) {
try (DirectoryStream<Path> children = Files.newDirectoryStream(stormCodeRoot)) {
for (Path child : children) {
if (Files.isDirectory(child)) {
String topologyId = child.getFileName().toString();
consumer.accept(child, topologyId);
}
}
}
}
}
代码示例来源:origin: testcontainers/testcontainers-java
private String determineDockerConfigPath() {
String dockerConfigEnv = System.getenv(DOCKER_CONFIG_ENV);
String dockerConfigProperty = System.getProperty(DOCKER_CONFIG_PROPERTY);
Path dockerConfig = Paths.get(System.getProperty("user.home"), ".docker", "config.json");
if (dockerConfigEnv != null && !dockerConfigEnv.trim().isEmpty() && Files.exists(Paths.get(dockerConfigEnv))) {
return dockerConfigEnv;
} else if (dockerConfigProperty != null && !dockerConfigProperty.trim().isEmpty() && Files.exists(Paths.get(dockerConfigProperty))) {
return dockerConfigProperty;
} else if (Files.exists(dockerConfig)) {
return dockerConfig.toString();
} else {
return null;
}
}
代码示例来源: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: 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: 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: org.codehaus.plexus/plexus-utils
public static File createSymbolicLink( File symlink, File target )
throws IOException
{
Path link = symlink.toPath();
if ( Files.exists( link, LinkOption.NOFOLLOW_LINKS ) )
{
Files.delete( link );
}
link = Files.createSymbolicLink( link, target.toPath() );
return link.toFile();
}
代码示例来源: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: btraceio/btrace
private static void appendToBootClassPath(Path libFolder) {
Path bootLibs = libFolder.resolve("boot");
if (Files.exists(bootLibs)) {
for (File f : bootLibs.toFile().listFiles()) {
if (f.getName().toLowerCase().endsWith(".jar")) {
try {
if (isDebug()) {
debugPrint("Adding " + f.getAbsolutePath() + " to bootstrap classpath");
}
inst.appendToBootstrapClassLoaderSearch(new JarFile(f));
} catch (IOException e) {
}
}
}
}
}
代码示例来源:origin: apache/ignite
/**
* Answers if the given path denotes existing directory.
*
* @param path The directory path.
* @return {@code True} if the given path denotes an existing directory.
*/
public static boolean exists(String path) {
if (F.isEmpty(path))
return false;
Path p = Paths.get(path);
return Files.exists(p) && Files.isDirectory(p) && Files.isReadable(p);
}
代码示例来源: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: apache/storm
@VisibleForTesting
static long localVersionOfBlob(Path versionFile) {
long currentVersion = -1;
if (Files.exists(versionFile) && !(Files.isDirectory(versionFile))) {
try (BufferedReader br = new BufferedReader(new FileReader(versionFile.toFile()))) {
String line = br.readLine();
currentVersion = Long.parseLong(line);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return currentVersion;
}
代码示例来源:origin: GoogleContainerTools/jib
private JavaContainerBuilder addDirectory(
Path directory, AbsoluteUnixPath destination, LayerType layerType, Predicate<Path> pathFilter)
throws IOException {
if (!Files.exists(directory)) {
throw new NoSuchFileException(directory.toString());
}
if (!Files.isDirectory(directory)) {
throw new NotDirectoryException(directory.toString());
}
layerConfigurationsBuilder.addDirectoryContents(layerType, directory, pathFilter, destination);
classpath.add(destination.toString());
return this;
}
}
代码示例来源:origin: dadoonet/fscrawler
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
Path targetPath = destination.resolve(rootPath.relativize(dir).toString());
if (!Files.exists(targetPath)) {
Files.createDirectory(targetPath);
}
return FileVisitResult.CONTINUE;
}
代码示例来源:origin: neo4j/neo4j
private void validatePath( Path path ) throws FileSystemException
{
if ( exists( path ) )
{
throw new FileAlreadyExistsException( path.toString() );
}
checkWritableDirectory( path.getParent() );
}
代码示例来源:origin: pmd/pmd
public RuleDocGenerator(FileWriter writer, Path root) {
this.writer = Objects.requireNonNull(writer, "A file writer must be provided");
this.root = Objects.requireNonNull(root, "Root directory must be provided");
Path docsDir = root.resolve("docs");
if (!Files.exists(docsDir) || !Files.isDirectory(docsDir)) {
throw new IllegalArgumentException("Couldn't find \"docs\" subdirectory");
}
}
代码示例来源: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: 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;
}
内容来源于网络,如有侵权,请联系作者删除!