當前位置: 首頁>>代碼示例>>Java>>正文


Java Files.exists方法代碼示例

本文整理匯總了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;
}
 
開發者ID:google,項目名稱:ios-device-control,代碼行數:22,代碼來源:SimulatorDeviceHost.java

示例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;
}
 
開發者ID:redlink-gmbh,項目名稱:smarti,代碼行數:17,代碼來源:WikipediaDeIndexConfiguration.java

示例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<>();
}
 
開發者ID:anthonyraymond,項目名稱:joal,代碼行數:17,代碼來源:TorrentFileProvider.java

示例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());
}
 
開發者ID:FerusTech,項目名稱:Amicus,代碼行數:17,代碼來源:YamlConfigFile.java

示例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());
                }
            }
        }
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:25,代碼來源:GatewayMetaState.java

示例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);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:31,代碼來源:KeyStoreWrapper.java

示例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()] );
}
 
開發者ID:chipKIT32,項目名稱:chipKIT-importer,代碼行數:21,代碼來源:ArduinoBuilderRunner.java

示例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();
    }
}
 
開發者ID:Aquerr,項目名稱:EagleFactions,代碼行數:23,代碼來源:MainConfig.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:ShellFolder.java

示例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);
        }
    }
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:10,代碼來源:ProjectUpdater.java

示例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);
    }
}
 
開發者ID:kamax-io,項目名稱:mxisd,代碼行數:31,代碼來源:KeyManager.java

示例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);
}
 
開發者ID:dizitart,項目名稱:nitrite-database,代碼行數:35,代碼來源:NitriteManager.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:JmodTask.java

示例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;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:29,代碼來源:ModuleTest.java

示例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.");
    }
}
 
開發者ID:nla,項目名稱:httrack2warc,代碼行數:10,代碼來源:HttrackCrawl.java


注:本文中的java.nio.file.Files.exists方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。