Java Path File Check nio isValidFileType(Path filePath)

Here you can find the source of isValidFileType(Path filePath)

Description

Checks if the given file path is valid for monitoring (i.e is a class or resource file).

License

Open Source License

Parameter

Parameter Description
filePath a Path instance representing a valid path

Return

true if the file is a class file or a resource file, false otherwise

Declaration

public static boolean isValidFileType(Path filePath) 

Method Source Code

//package com.java2s;
/**//from  ww w  .j a  v  a2s  .  c om
 * ****************************************************************************
 * Copyright (c) 2005-2014 Faur Ioan-Aurel.                                     *
 * All rights reserved. This program and the accompanying materials             *
 * are made available under the terms of the MIT License                        *
 * which accompanies this distribution, and is available at                     *
 * http://opensource.org/licenses/MIT                                           *
 * *
 * For any issues or questions send an email at: fioan89@gmail.com              *
 * *****************************************************************************
 */

import java.nio.file.Path;

public class Main {
    /**
     * A list of file types extensions that can be watched for different events like
     * creation, modification and remove.
     */
    public static final String[] fileTypesToWatch = { ".class", ".properties" };

    /**
     * Checks if the given file path is valid for monitoring (i.e is a class or resource file).
     *
     * @param filePath a {@link Path} instance representing a valid path
     * @return {@code true} if the file is a class file or a resource file, {@code false} otherwise
     */
    public static boolean isValidFileType(Path filePath) {
        for (String fileType : fileTypesToWatch) {
            if (filePath != null && filePath.getFileName().toString().endsWith(fileType)) {
                return true;
            }
        }

        return false;
    }
}

Related

  1. isSameFile(Path path1, Path path2)
  2. isSteadyStateReached(Path integrationStepFile, double minStepAtEndOfStabilization)
  3. isUNC(Path inputPath)
  4. isUnix(Path path)
  5. isValidDirectory(String path)
  6. isValidHomeDirectory(final Path path)
  7. isValidPath(String path)
  8. isValidPath(String path)
  9. isValidPath(String path)