本文整理汇总了Java中java.nio.file.Files.exists方法的典型用法代码示例。如果您正苦于以下问题:Java Files.exists方法的具体用法?Java Files.exists怎么用?Java Files.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.Files
的用法示例。
在下文中一共展示了Files.exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runtimeRootPath
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Depending on how the runtime is installed, the applications folder and system version
* information can be located in one of two paths. The SDK path is used if it exists, otherwise
* the simruntime directory is created on boot if it does not exist and is then used.
*/
private static Path runtimeRootPath(String productVersion) {
Path runtimeRoot =
Paths.get(
"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform"
+ "/Developer/SDKs/iPhoneSimulator"
+ productVersion
+ ".sdk");
if (!Files.exists(runtimeRoot)) {
runtimeRoot =
Paths.get(
"/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS "
+ productVersion
+ ".simruntime/Contents/Resources/RuntimeRoot");
}
return runtimeRoot;
}
示例2: getWikipediaDeCoreDescriptor
import java.nio.file.Files; //导入方法依赖的package包/类
@Bean(name=WIKIPEDIA_DE)
protected SolrCoreDescriptor getWikipediaDeCoreDescriptor() throws IOException {
log.info("init CoreDescriptor with resource '{}'", wikipediaDeResource);
SimpleCoreDescriptor cd = new SimpleCoreDescriptor(WIKIPEDIA_DE, Paths.get(wikipediaDeResource)){
@Override
public void initCoreDirectory(Path coreDir, Path sharedLibDir) throws IOException {
if(!Files.exists(coreDir.resolve("core.properties"))){
log.debug("copying wikipedia-de solr core to {}", coreDir);
super.initCoreDirectory(coreDir, sharedLibDir);
} else { //TODO: check version based on version number in core.properties
log.info("using existing wikipedia-de solr core (if you want to update delete '{}' and restart)", coreDir);
}
}
};
return cd;
}
示例3: TorrentFileProvider
import java.nio.file.Files; //导入方法依赖的package包/类
public TorrentFileProvider(final String confFolder, final ApplicationEventPublisher publisher) throws FileNotFoundException {
if (StringUtils.isBlank(confFolder)) {
throw new IllegalArgumentException("A config path is required.");
}
this.torrentFolder = Paths.get(confFolder).resolve("torrents");
if (!Files.exists(torrentFolder)) {
logger.error("Folder " + torrentFolder.toAbsolutePath() + " does not exists.");
throw new FileNotFoundException(String.format("Torrent folder '%s' not found.", torrentFolder.toAbsolutePath()));
}
this.publisher = publisher;
this.archiveFolder = torrentFolder.resolve("archived");
this.torrentFiles = Collections.synchronizedMap(new HashMap<File, MockedTorrent>());
this.watcher = new TorrentFileWatcher(this, torrentFolder);
this.torrentFileChangeListener = new HashSet<>();
}
示例4: load
import java.nio.file.Files; //导入方法依赖的package包/类
public static YamlConfigFile load(@Nonnull final Path path,
@Nullable final String resource,
final boolean overwrite) throws IOException {
if (overwrite) {
Files.deleteIfExists(path);
}
if (!Files.exists(path)) {
Files.createDirectories(path.getParent());
Files.copy(YamlConfigFile.class.getResourceAsStream(resource), path);
}
final YAMLConfigurationLoader fileLoader = YAMLConfigurationLoader.builder().setPath(path).build();
return new YamlConfigFile(path, fileLoader, fileLoader.load());
}
示例5: ensureNoPre019State
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Throws an IAE if a pre 0.19 state is detected
*/
private void ensureNoPre019State() throws Exception {
for (Path dataLocation : nodeEnv.nodeDataPaths()) {
final Path stateLocation = dataLocation.resolve(MetaDataStateFormat.STATE_DIR_NAME);
if (!Files.exists(stateLocation)) {
continue;
}
try (DirectoryStream<Path> stream = Files.newDirectoryStream(stateLocation)) {
for (Path stateFile : stream) {
if (logger.isTraceEnabled()) {
logger.trace("[upgrade]: processing [" + stateFile.getFileName() + "]");
}
final String name = stateFile.getFileName().toString();
if (name.startsWith("metadata-")) {
throw new IllegalStateException("Detected pre 0.19 metadata file please upgrade to a version before "
+ Version.CURRENT.minimumCompatibilityVersion()
+ " first to upgrade state structures - metadata found: [" + stateFile.getParent().toAbsolutePath());
}
}
}
}
}
示例6: load
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Loads information about the Elasticsearch keystore from the provided config directory.
*
* {@link #decrypt(char[])} must be called before reading or writing any entries.
* Returns {@code null} if no keystore exists.
*/
public static KeyStoreWrapper load(Path configDir) throws IOException {
Path keystoreFile = keystorePath(configDir);
if (Files.exists(keystoreFile) == false) {
return null;
}
SimpleFSDirectory directory = new SimpleFSDirectory(configDir);
try (IndexInput indexInput = directory.openInput(KEYSTORE_FILENAME, IOContext.READONCE)) {
ChecksumIndexInput input = new BufferedChecksumIndexInput(indexInput);
CodecUtil.checkHeader(input, KEYSTORE_FILENAME, FORMAT_VERSION, FORMAT_VERSION);
byte hasPasswordByte = input.readByte();
boolean hasPassword = hasPasswordByte == 1;
if (hasPassword == false && hasPasswordByte != 0) {
throw new IllegalStateException("hasPassword boolean is corrupt: "
+ String.format(Locale.ROOT, "%02x", hasPasswordByte));
}
String type = input.readString();
String secretKeyAlgo = input.readString();
byte[] keystoreBytes = new byte[input.readInt()];
input.readBytes(keystoreBytes, 0, keystoreBytes.length);
CodecUtil.checkFooter(input);
return new KeyStoreWrapper(hasPassword, type, secretKeyAlgo, keystoreBytes);
}
}
示例7: createDependencyResolutionCommand
import java.nio.file.Files; //导入方法依赖的package包/类
private String[] createDependencyResolutionCommand( Path gccPath, Path corePath, Path variantPath, List<Path> libraryPaths, Path file ) {
List <String> commandElements = new ArrayList<>();
commandElements.add( gccPath.toString() );
commandElements.add( "-I" );
commandElements.add( corePath.toString() );
commandElements.add( "-I" );
commandElements.add( variantPath.toString() );
for ( Path libPath : libraryPaths ) {
commandElements.add( "-I" );
commandElements.add( libPath.toAbsolutePath().toString() );
Path utilityPath = libPath.resolve("utility");
if ( Files.exists(utilityPath) ) {
commandElements.add( "-I" );
commandElements.add( utilityPath.toAbsolutePath().toString() );
}
}
commandElements.add( "-MM" );
commandElements.add( file.toAbsolutePath().toString() );
return commandElements.toArray( new String[commandElements.size()] );
}
示例8: setup
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public void setup()
{
if (! Files.exists(configFile))
{
try
{
Files.createFile(configFile);
load();
populate();
save();
}
catch (IOException e)
{
e.printStackTrace();
}
}
else
{
load();
}
}
示例9: getShellFolder
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Return a shell folder from a file object
* @exception FileNotFoundException if file does not exist
*/
public static ShellFolder getShellFolder(File file) throws FileNotFoundException {
if (file instanceof ShellFolder) {
return (ShellFolder)file;
}
if (!Files.exists(Paths.get(file.getPath()), LinkOption.NOFOLLOW_LINKS)) {
throw new FileNotFoundException();
}
return shellFolderManager.createShellFolder(file);
}
示例10: safeCleanProjectDir
import java.nio.file.Files; //导入方法依赖的package包/类
private void safeCleanProjectDir(Path dirTmp) throws IOException {
for (WORK_DIR_NAMES subdirName : WORK_DIR_NAMES.values()) {
String sSubdirName = subdirName.toString();
Path dirOld = dirExport.resolve(sSubdirName);
if (Files.exists(dirOld)) {
Files.move(dirOld, dirTmp.resolve(sSubdirName), StandardCopyOption.ATOMIC_MOVE);
}
}
}
示例11: build
import java.nio.file.Files; //导入方法依赖的package包/类
@PostConstruct
public void build() {
try {
keySpecs = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.CURVE_ED25519_SHA512);
signEngine = new EdDSAEngine(MessageDigest.getInstance(keySpecs.getHashAlgorithm()));
keys = new ArrayList<>();
Path privKey = Paths.get(keyCfg.getPath());
if (!Files.exists(privKey)) {
KeyPair pair = (new KeyPairGenerator()).generateKeyPair();
String keyEncoded = Base64.getEncoder().encodeToString(pair.getPrivate().getEncoded());
FileUtils.writeStringToFile(privKey.toFile(), keyEncoded, StandardCharsets.ISO_8859_1);
keys.add(pair);
} else {
if (Files.isDirectory(privKey)) {
throw new RuntimeException("Invalid path for private key: " + privKey.toString());
}
if (Files.isReadable(privKey)) {
byte[] seed = Base64.getDecoder().decode(FileUtils.readFileToString(privKey.toFile(), StandardCharsets.ISO_8859_1));
EdDSAPrivateKeySpec privKeySpec = new EdDSAPrivateKeySpec(seed, keySpecs);
EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(privKeySpec.getA(), keySpecs);
keys.add(new KeyPair(new EdDSAPublicKey(pubKeySpec), new EdDSAPrivateKey(privKeySpec)));
}
}
} catch (NoSuchAlgorithmException | IOException e) {
throw new RuntimeException(e);
}
}
示例12: createSampleDb
import java.nio.file.Files; //导入方法依赖的package包/类
private void createSampleDb() {
String dbFilePath = Paths.get("").toAbsolutePath().toString() + "/sample.db";
if (!Files.exists(Paths.get(dbFilePath))) {
Nitrite db = Nitrite.builder()
.filePath(dbFilePath)
.openOrCreate();
ObjectRepository<Company> companyRepository = db.getRepository(Company.class);
ObjectRepository<Employee> employeeRepository = db.getRepository(Employee.class);
Employee[] dummy = new Employee[0];
for (int i = 0; i < 10; i++) {
Company company = DataGenerator.generateCompanyRecord();
companyRepository.insert(company);
for (List<Employee> employeeList : company.getEmployeeRecord().values()) {
if (employeeList != null && !employeeList.isEmpty()) {
employeeRepository.insert(employeeList.toArray(dummy));
}
}
}
db.commit();
db.close();
} else {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Sample Database");
alert.setHeaderText("Sample Database Already Exists");
alert.getDialogPane().setContent(new Label(dbFilePath));
alert.showAndWait();
}
dbFile.setText(dbFilePath);
}
示例13: convert
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public Path convert(String value) {
try {
Path path = CWD.resolve(value);
if (Files.exists(path)) {
if (!Files.isDirectory(path))
throw new CommandException("err.cannot.create.dir", path);
}
return path;
} catch (InvalidPathException x) {
throw new CommandException("err.path.not.valid", value);
}
}
示例14: getModulesRoot
import java.nio.file.Files; //导入方法依赖的package包/类
private static Path getModulesRoot() {
try {
final File javaHome = new File(JDK9_HOME == null ? System.getProperty("java.home") : JDK9_HOME); //NOI18N
final File jrtProvider = new File(new File(javaHome, "lib"), "jrt-fs.jar"); //NOI18N
if (!jrtProvider.exists()) {
return null;
}
final ClassLoader cl = new URLClassLoader(
new URL[]{jrtProvider.toURI().toURL()},
ModuleTest.class.getClassLoader());
FileSystemProvider provider = null;
for (FileSystemProvider p : ServiceLoader.load(FileSystemProvider.class, cl)) {
if ("jrt".equals(p.getScheme())) { //NOI18N
provider = p;
break;
}
}
if (provider == null) {
return null;
}
final Path jimageRoot = provider.getPath(URI.create("jrt:///")); //NOI18N
final Path modules = jimageRoot.resolve("modules");
return Files.exists(modules) ? modules : jimageRoot;
} catch (IOException ioe) {
LOG.log(Level.WARNING, "Cannot load jrt nio provider.", ioe); //NOI18N
return null;
}
}
示例15: forEach
import java.nio.file.Files; //导入方法依赖的package包/类
public void forEach(RecordConsumer action) throws IOException {
if (Files.exists(dir.resolve("hts-cache/new.txt"))) {
forEachByTxt(action);
} else if (Files.exists(dir.resolve("logs/debug"))) {
forEachByDebugLogs(action);
} else {
throw new IOException("Both hts-cache/new.txt and logs/debug are missing. I can't handle this crawl.");
}
}