Class FileUtil


  • public final class FileUtil
    extends Object
    This is a utility class for working with Files.
    • Method Detail

      • getFileNameWithoutExtension

        public static String getFileNameWithoutExtension​(String fileName)
        Helper method to get a filename without its extension
        Parameters:
        fileName - String
        Returns:
        String
      • normalizeFilename

        public static String normalizeFilename​(String fileName)
        Normalizes the filename by taking the casing into account, e.g. on Windows, the filename is changed to lowercase only.
        Parameters:
        fileName - the file name
        Returns:
        the normalized file name
      • findPatternInFile

        public static boolean findPatternInFile​(File file,
                                                String pattern)
        Handy method to find a certain pattern into a file. While this method lives in the FileUtils, it was designed with with unit test in mind (to check result redirected into a file)
        Parameters:
        file -
        pattern -
        Returns:
      • readFilelistEntries

        public static List<Path> readFilelistEntries​(Path filelist)
                                              throws IOException
        Reads the file, which contains the filelist. This is used for the command line arguments --filelist/-filelist for both PMD and CPD. The separator in the filelist is a comma and/or newlines.
        Parameters:
        filelist - the file which contains the list of path names
        Returns:
        a list of file paths
        Throws:
        IOException - if the file couldn't be read