Class XFile


  • public class XFile
    extends java.lang.Object
    This class is used for opening and reading files that are stored in OEM ASCII or Ansi character set. It also contains a few utility functions.

    New functions to create a buffered FileReader and FileWriter using different encodings is now also available. See the methods createFileReader and createFileWriter.

    Author:
    Christopher Mindus
    • Field Summary

      Fields 
      Modifier and TypeFieldDescription
      static java.lang.String[]dayNames
      The month names.
      static java.lang.String[]monthNames
      The month names.
    • Constructor Summary

      Constructors 
      ConstructorDescription
      XFile​(byte[] data)
      Creates a new instance of a file in memory.
      XFile​(byte[] data, XFile openFile)
      Creates a new instance of a file in memory.
      XFile​(byte[] data, java.lang.String fileName)
      Creates a new instance of a file in memory.
      XFile​(XFile file, int position)
      Opens a new instance of a file at a specified file position.
      XFile​(java.io.File file)
      Creates a new instance of a file from an input stream, typically from ZIP/JAR files.
      XFile​(java.io.InputStream in)
      Creates a new instance of a file from an input stream, typically from ZIP/JAR files.
      XFile​(java.io.InputStream in, java.lang.String fileName)
      Creates a new instance of a file from an input stream, typically from ZIP/JAR files.
      XFile​(java.lang.String fileName)
      Opens the specified file for read.
      XFile​(java.lang.String fileName, boolean doSearchPath)
      Opens the specified file for read.
      XFile​(java.lang.String fileName, XFile openFile)
      Opens the specified file for read.
      XFile​(java.lang.String fileName, java.lang.String previousFile)
      Opens the specified file for read.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      voidclose()
      Close stream and file.
      static booleandeleteFileAndChildren​(java.io.File dir)
      Deletes a file or directory along with all its children (in case of a directory).
      static java.lang.StringfindFileInDirectory​(java.io.File dir, java.lang.String fileName, boolean matchCase)
      Finds a file in a directory or in one of it's sub-directories.
      static java.lang.StringfindFileInDirectory​(java.lang.String dir, java.lang.String fileName, boolean matchCase)
      Finds a file in a directory or in one of it's sub-directories.
      static java.lang.StringfindFileInPath​(java.lang.String fileName)
      Locates the specified file.
      static java.lang.StringfindFileInPath​(java.lang.String fileName, boolean doSearchPath)
      Locates the specified file.
      static intfindFilesInDirectory​(java.io.File dir, java.util.ArrayList<java.lang.String> fileNames, boolean matchCase)
      Finds a file in a directory or in one of it's sub-directories.
      static intfindFilesInDirectory​(java.lang.String dir, java.util.ArrayList<java.lang.String> fileNames, boolean matchCase)
      Finds a file in a directory or in one of it's sub-directories.
      static java.lang.StringgetBaseName​(java.lang.String fn)
      Gets the base file name without path and file extension.
      static java.lang.StringgetFileExtension​(java.io.File file)
      Gets the extension of a file.
      static java.lang.StringgetFileExtension​(java.lang.String fileName)
      Gets the extension of a file.
      java.lang.StringgetFileName()
      Gets the file name.
      java.lang.StringgetFileNameFromAnother​(java.lang.String base)
      Returns a file name and path that is taken from the current XFile instance with path, but with the base name of the file name in XFile.
      static java.lang.StringgetFileNameFromAnother​(java.lang.String base, java.lang.String another)
      Returns a file name and path that is taken from a file with path, but with the base name of another file.
      java.lang.StringgetFileTimestamp()
      Get file time stamp as DayName Month day HH:MM:SS year.
      static java.lang.StringgetFileTimestamp​(long lastModified)
      Get file time stamp as DayName Month day HH:MM:SS year.
      static java.lang.StringgetFileTimestamp​(java.lang.String fileName)
      Get file time stamp as DayName Month day HH:MM:SS year.
      bytegetMemoryDataByte()
      Gets the current byte from the memory data (same as readByte but without advancing the position).
      static java.lang.StringgetRelativeFileName​(java.lang.String fileName, java.lang.String reference)
      Gets the relative file name from another file (if possible).
      static java.lang.StringgetRelativeFileName​(java.lang.String fileName, java.lang.String reference, boolean mustBeChildOrSibling, boolean stripRelativePath, boolean mustExist, boolean mustBeFile)
      Gets a file name relative to a reference file name.
      static java.lang.StringgetRelativePath​(java.io.File home, java.io.File f)
      Get relative path of File 'f' with respect to 'home' directory.
      intgetRemainingSize()
      Gets the remaining size in the memory file.
      static booleanhasFileExtension​(java.io.File file, boolean caseSensitive, java.lang.String... extensions)
      Checks the extension of a file for a valid one with the ones specified in the list of extensions.
      static booleanhasFileExtension​(java.lang.String fileName, boolean caseSensitive, java.lang.String... extensions)
      Checks the extension of a file for a valid one with the ones specified in the list of extensions.
      static booleanisJarOrZipFile​(java.io.File file)
      Checks if a file is of Jar or Zip file type (i.e.
      static booleanisJarOrZipFile​(java.lang.String fileName)
      Checks if a file is of Jar or Zip file type (i.e.
      static booleanisSameFile​(java.io.File f1, java.io.File f2)
      Checks if two file names refer to the same file, i.e.
      static booleanisSameFile​(java.lang.String fn1, java.lang.String fn2)
      Checks if two file names refer to the same file, i.e.
      longlastModified()
      Returns the time that the file represented by this file object was last modified.
      static booleanlistDirectory​(java.io.File dir, java.util.ArrayList<java.io.File> array)
      Gets a directory listing including all children and sub-directories.
      static booleanlistDirectory​(java.io.File dir, java.util.ArrayList<java.io.File> array, boolean includeDirectories)
      Gets a directory listing including all children and sub-directories.
      static booleanlistDirectory​(java.lang.String dir, java.util.ArrayList<java.io.File> array)
      Gets a directory listing including all children and sub-directories.
      static booleanlistDirectory​(java.lang.String dir, java.util.ArrayList<java.io.File> array, boolean includeDirectories)
      Gets a directory listing including all children and sub-directories.
      static byte[]loadFile​(XFile file)
      Loads a file into memory.
      static byte[]loadFile​(java.io.File file)
      Loads a file into memory.
      static byte[]loadFile​(java.io.InputStream in)
      Loads a file into memory.
      static byte[]loadFile​(java.lang.String fileName)
      Loads a file into memory.
      static byte[]loadFile​(java.util.jar.JarFile jar, java.util.jar.JarEntry je)
      Loads a file into memory.
      byte[]read​(int size)
      Reads a number of bytes from the file.
      java.lang.StringreadAnsiLine()
      Reads a line in the file up to the next new line (CR/LF or just LF) or the end of the file.
      intreadByte()
      Reads an unsigned byte value from the file.
      byte[]readByteLine()
      Reads a line in the file up to the next new line (CR/LF or just LF) or the end of the file.
      doublereadIntelDouble()
      Reads a double value from the file.
      intreadIntelLong()
      Reads a signed long value from the file in Intel style.
      intreadIntelShort()
      Reads an signed short value from the file in Intel style.
      intreadIntelUShort()
      Reads an unsigned short value from the file in Intel style.
      java.lang.StringreadISOLine()
      Reads a line in the file up to the next new line (CR/LF or just LF) or the end of the file.
      java.lang.StringreadOEMBytes​(int size)
      Reads a number of OEM bytes and returns it as a string.
      java.lang.StringreadOEMLine()
      Reads a line in the file up to the next new line (CR/LF or just LF) or the end of the file.
      java.lang.StringreadOEMString()
      Reads a number of OEM bytes and returns it as a string.
      java.lang.StringreadOEMString​(int size)
      Reads a number of OEM bytes and returns it as a string.
      java.util.Vector<java.lang.String>readOEMStringVector​(boolean skipEmptyLines)
      Reads the file until end as a string vector.
      java.util.Vector<java.lang.String>readOEMStringVector​(boolean skipEmptyLines, boolean trimLines)
      Reads the file until end as a string vector.
      java.util.Vector<java.lang.String>readOEMStringVector​(boolean skipEmptyLines, boolean trimLeading, boolean trimTrailing)
      Reads the file until end as a string vector.
      java.lang.StringreadString()
      Reads a number of bytes and returns it as a string.
      java.lang.StringreadString​(int size)
      Reads a number of bytes and returns it as a string.
      java.lang.StringreadUnicodeChars​(int size)
      Reads a number of Unicode characters (16-bit words) and returns it as a string.
      java.lang.StringreadUnicodeString()
      Reads a number of Unicode characters (16-bit words) and returns it as a string.
      java.lang.StringreadUnicodeString​(int size)
      Reads a number of Unicode characters (16-bit words) and returns it as a string.
      voidskipBytes​(int n)
      Skips a number of bytes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • monthNames

        public static final java.lang.String[] monthNames
        The month names.
      • dayNames

        public static final java.lang.String[] dayNames
        The month names.
    • Constructor Detail

      • XFile

        public XFile​(java.lang.String fileName)
              throws java.io.IOException
        Opens the specified file for read.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • XFile

        public XFile​(java.lang.String fileName,
                     boolean doSearchPath)
              throws java.io.IOException
        Opens the specified file for read. The file can be located in the Java Class Path, but not in any archives (zip/jar). If the file name contains a relative or absolute path, the path will not be searched.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • XFile

        public XFile​(java.lang.String fileName,
                     XFile openFile)
              throws java.io.IOException
        Opens the specified file for read. The directory of the file name is taken from the instance of the XFile passed into this method.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • XFile

        public XFile​(java.lang.String fileName,
                     java.lang.String previousFile)
              throws java.io.IOException
        Opens the specified file for read. The directory of the file name is taken from the file name passed into this method.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • XFile

        public XFile​(XFile file,
                     int position)
              throws java.io.IOException
        Opens a new instance of a file at a specified file position.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • XFile

        public XFile​(byte[] data)
        Creates a new instance of a file in memory.
      • XFile

        public XFile​(byte[] data,
                     java.lang.String fileName)
        Creates a new instance of a file in memory.
      • XFile

        public XFile​(byte[] data,
                     XFile openFile)
        Creates a new instance of a file in memory. The file name is taken from the current open file.
      • XFile

        public XFile​(java.io.InputStream in)
        Creates a new instance of a file from an input stream, typically from ZIP/JAR files.
      • XFile

        public XFile​(java.io.InputStream in,
                     java.lang.String fileName)
        Creates a new instance of a file from an input stream, typically from ZIP/JAR files.
      • XFile

        public XFile​(java.io.File file)
              throws java.io.FileNotFoundException
        Creates a new instance of a file from an input stream, typically from ZIP/JAR files.
        Throws:
        java.io.FileNotFoundException - if file is not found.
    • Method Detail

      • loadFile

        public static byte[] loadFile​(java.io.InputStream in)
                               throws java.io.IOException
        Loads a file into memory.
        Parameters:
        in - the input stream.
        Returns:
        null for out of memory.
        Throws:
        java.io.FileNotFoundException - if the file cannot be found.
        java.io.IOException - if the file cannot be loaded.
      • loadFile

        public static byte[] loadFile​(XFile file)
                               throws java.io.IOException
        Loads a file into memory.
        Returns:
        null for out of memory.
        Throws:
        java.io.FileNotFoundException - if the file cannot be found.
        java.io.IOException - if the file cannot be loaded.
      • loadFile

        public static byte[] loadFile​(java.lang.String fileName)
                               throws java.io.IOException
        Loads a file into memory.
        Returns:
        null for out of memory.
        Throws:
        java.io.FileNotFoundException - if the file cannot be found.
        java.io.IOException - if the file cannot be loaded.
      • loadFile

        public static byte[] loadFile​(java.io.File file)
                               throws java.io.IOException
        Loads a file into memory.
        Returns:
        null for out of memory.
        Throws:
        java.io.FileNotFoundException - if the file cannot be found.
        java.io.IOException - if the file cannot be loaded.
      • loadFile

        public static byte[] loadFile​(java.util.jar.JarFile jar,
                                      java.util.jar.JarEntry je)
                               throws java.io.IOException
        Loads a file into memory.
        Returns:
        null for out of memory.
        Throws:
        java.io.FileNotFoundException - if the file cannot be found.
        java.io.IOException - if the file cannot be loaded.
      • close

        public void close()
        Close stream and file.
      • getFileNameFromAnother

        public static java.lang.String getFileNameFromAnother​(java.lang.String base,
                                                              java.lang.String another)
        Returns a file name and path that is taken from a file with path, but with the base name of another file. If the new base file name starts with a file name separator as "/path/filename", and is therefore not relative as "./path/filename" or "path/filename", the path of the other file is not used. This is also valid for drive specification such as "c:\path\filename" or "unit:/path/filename".
      • getFileNameFromAnother

        public java.lang.String getFileNameFromAnother​(java.lang.String base)
        Returns a file name and path that is taken from the current XFile instance with path, but with the base name of the file name in XFile.
      • read

        public byte[] read​(int size)
                    throws java.io.IOException
        Reads a number of bytes from the file.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • readString

        public java.lang.String readString()
                                    throws java.io.IOException
        Reads a number of bytes and returns it as a string. The string ends if a zero-termination character is encountered. The string is assumed to be in default Ansi code page.
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        readOEMString()
      • readString

        public java.lang.String readString​(int size)
                                    throws java.io.IOException
        Reads a number of bytes and returns it as a string. The string ends if a zero-termination character is encountered. The string is assumed to be in default Ansi code page. Note: The entire string is read from the file as specified by the size.
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        readOEMString()
      • readOEMString

        public java.lang.String readOEMString()
                                       throws java.io.IOException
        Reads a number of OEM bytes and returns it as a string. The string ends if a zero-termination character is encountered. Note: conversion is done from the current code page to Unicode.
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        readString(), readOEMBytes(int)
      • readOEMString

        public java.lang.String readOEMString​(int size)
                                       throws java.io.IOException
        Reads a number of OEM bytes and returns it as a string. The string ends if a zero-termination character is encountered. Note: conversion is done from the current code page to Unicode. Note: The entire string is read from the file as specified by the size.
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        readString(), readOEMBytes(int)
      • readUnicodeString

        public java.lang.String readUnicodeString​(int size)
                                           throws java.io.IOException
        Reads a number of Unicode characters (16-bit words) and returns it as a string. The string ends as soon as a zero-character is read.
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        read(int), readOEMString()
      • readUnicodeString

        public java.lang.String readUnicodeString()
                                           throws java.io.IOException
        Reads a number of Unicode characters (16-bit words) and returns it as a string. The string ends as soon as a zero-character is read.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • readOEMBytes

        public java.lang.String readOEMBytes​(int size)
                                      throws java.io.IOException
        Reads a number of OEM bytes and returns it as a string. Note: conversion is done from the current code page to Unicode.
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        read(int), readOEMString()
      • readUnicodeChars

        public java.lang.String readUnicodeChars​(int size)
                                          throws java.io.IOException
        Reads a number of Unicode characters (16-bit words) and returns it as a string. The string ends as soon as a zero-character is read.
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        read(int), readOEMString()
      • readByte

        public int readByte()
                     throws java.io.IOException
        Reads an unsigned byte value from the file.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • readIntelUShort

        public int readIntelUShort()
                            throws java.io.IOException
        Reads an unsigned short value from the file in Intel style.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • readIntelShort

        public int readIntelShort()
                           throws java.io.IOException
        Reads an signed short value from the file in Intel style.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • readIntelLong

        public int readIntelLong()
                          throws java.io.IOException
        Reads a signed long value from the file in Intel style.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • readIntelDouble

        public double readIntelDouble()
                               throws java.io.IOException
        Reads a double value from the file.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • skipBytes

        public void skipBytes​(int n)
                       throws java.io.IOException
        Skips a number of bytes.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • getRemainingSize

        public int getRemainingSize()
        Gets the remaining size in the memory file. It returns an estimate of what is "available()" when an input stream is used.
      • getFileName

        public java.lang.String getFileName()
        Gets the file name. This method may return null if the instance of this object is created from a byte array.
      • readOEMStringVector

        public java.util.Vector<java.lang.String> readOEMStringVector​(boolean skipEmptyLines)
                                                               throws java.io.IOException
        Reads the file until end as a string vector.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • readOEMStringVector

        public java.util.Vector<java.lang.String> readOEMStringVector​(boolean skipEmptyLines,
                                                                      boolean trimLines)
                                                               throws java.io.IOException
        Reads the file until end as a string vector.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • readOEMStringVector

        public java.util.Vector<java.lang.String> readOEMStringVector​(boolean skipEmptyLines,
                                                                      boolean trimLeading,
                                                                      boolean trimTrailing)
                                                               throws java.io.IOException
        Reads the file until end as a string vector.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • readByteLine

        public byte[] readByteLine()
                            throws java.io.IOException
        Reads a line in the file up to the next new line (CR/LF or just LF) or the end of the file.
        Returns:
        null for end of file.
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        XOutputFile.writeLine(byte[])
      • readOEMLine

        public java.lang.String readOEMLine()
                                     throws java.io.IOException
        Reads a line in the file up to the next new line (CR/LF or just LF) or the end of the file.
        Returns:
        null for end of file.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • readAnsiLine

        public java.lang.String readAnsiLine()
                                      throws java.io.IOException
        Reads a line in the file up to the next new line (CR/LF or just LF) or the end of the file.
        Returns:
        null for end of file.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • readISOLine

        public java.lang.String readISOLine()
                                     throws java.io.IOException
        Reads a line in the file up to the next new line (CR/LF or just LF) or the end of the file. The data in the file should be encoded in ISO 8859-1.

        Typically, this function is used to read data that have been written with XOutputFile.writeISOLine.

        Returns:
        null for end of file.
        Throws:
        java.io.IOException - if an I/O error occurs.
        See Also:
        XOutputFile.writeISOLine(java.lang.String)
      • getMemoryDataByte

        public byte getMemoryDataByte()
        Gets the current byte from the memory data (same as readByte but without advancing the position).
      • findFileInPath

        public static java.lang.String findFileInPath​(java.lang.String fileName)
        Locates the specified file. The file can be located in the Java Class Path, but not in any archives (zip/jar). If the file name contains a relative or absolute path, the path will not be searched.
        Returns:
        null if the file is not found.
      • findFileInPath

        public static java.lang.String findFileInPath​(java.lang.String fileName,
                                                      boolean doSearchPath)
        Locates the specified file. The file can be located in the Java Class Path, but not in any archives (zip/jar). If the file name contains a relative or absolute path, the path will not be searched.
        Returns:
        null if the file is not found.
      • findFileInDirectory

        public static java.lang.String findFileInDirectory​(java.lang.String dir,
                                                           java.lang.String fileName,
                                                           boolean matchCase)
        Finds a file in a directory or in one of it's sub-directories. This function performs variable substitution such as "%ProgramFiles%\firefox.exe" to search for the FireFox executable in the program files folder defined for the computer in the environment.
        Returns:
        the full path to the file, or null if not found or for errors in the variable substitution.
      • findFileInDirectory

        public static java.lang.String findFileInDirectory​(java.io.File dir,
                                                           java.lang.String fileName,
                                                           boolean matchCase)
        Finds a file in a directory or in one of it's sub-directories.
        Returns:
        the full path to the file, or null if not found.
      • findFilesInDirectory

        public static int findFilesInDirectory​(java.lang.String dir,
                                               java.util.ArrayList<java.lang.String> fileNames,
                                               boolean matchCase)
        Finds a file in a directory or in one of it's sub-directories. This function performs variable substitution such as "%ProgramFiles%\firefox.exe" to search for the FireFox executable in the program files folder defined for the computer in the environment. The parameter "dirDisplay" can be null [not present in XFile yet!].
        Returns:
        The count of files found, the original list is modified.
      • findFilesInDirectory

        public static int findFilesInDirectory​(java.io.File dir,
                                               java.util.ArrayList<java.lang.String> fileNames,
                                               boolean matchCase)
        Finds a file in a directory or in one of it's sub-directories. The parameter "dirDisplay" can be null [not present in XFile yet!].
        Returns:
        the count of files found.
      • lastModified

        public long lastModified()
        Returns the time that the file represented by this file object was last modified. The return value is system dependent and should only be used to compare with other values returned by last modified. It should not be interpreted as an absolute time.
        Returns:
        the time the file specified by this object was last modified, or 0L if the specified file does not exist.
      • getFileTimestamp

        public static java.lang.String getFileTimestamp​(java.lang.String fileName)
        Get file time stamp as DayName Month day HH:MM:SS year.
      • getFileTimestamp

        public java.lang.String getFileTimestamp()
        Get file time stamp as DayName Month day HH:MM:SS year.
      • getFileTimestamp

        public static java.lang.String getFileTimestamp​(long lastModified)
        Get file time stamp as DayName Month day HH:MM:SS year.
      • getBaseName

        public static java.lang.String getBaseName​(java.lang.String fn)
        Gets the base file name without path and file extension. This is typically used for the package name for Java code. The case of the base name is unchanged.
      • isSameFile

        public static boolean isSameFile​(java.lang.String fn1,
                                         java.lang.String fn2)
        Checks if two file names refer to the same file, i.e. has the same canonical file names.
      • isSameFile

        public static boolean isSameFile​(java.io.File f1,
                                         java.io.File f2)
        Checks if two file names refer to the same file, i.e. has the same canonical file names.
      • getRelativeFileName

        public static java.lang.String getRelativeFileName​(java.lang.String fileName,
                                                           java.lang.String reference,
                                                           boolean mustBeChildOrSibling,
                                                           boolean stripRelativePath,
                                                           boolean mustExist,
                                                           boolean mustBeFile)
                                                    throws java.io.IOException,
                                                           java.io.FileNotFoundException
        Gets a file name relative to a reference file name. The flag "mustBeChildOrSibling" is used to check that the file name is relative the reference, but is not "above" it. The files must exist.
        Returns:
        null for failure.
        Throws:
        java.io.IOException
        java.io.FileNotFoundException
      • getRelativePath

        public static java.lang.String getRelativePath​(java.io.File home,
                                                       java.io.File f)
                                                throws java.io.IOException
        Get relative path of File 'f' with respect to 'home' directory.
         example : home = /a/b/c
                   f    = /a/d/e/x.txt
                   s = getRelativePath(home,f) = ../../d/e/x.txt
         
        Parameters:
        home - base path, should be a directory, not a file, or it doesn't make sense.
        f - file to generate path for.
        Returns:
        path from home to f as a string
        Throws:
        java.io.IOException - for file failures.
      • getRelativeFileName

        public static java.lang.String getRelativeFileName​(java.lang.String fileName,
                                                           java.lang.String reference)
        Gets the relative file name from another file (if possible). The parameter "reference" can be seen as the "home" file or directory to make the other file ("filename") relative to.
      • listDirectory

        public static boolean listDirectory​(java.lang.String dir,
                                            java.util.ArrayList<java.io.File> array)
        Gets a directory listing including all children and sub-directories. Only files are added.
        Parameters:
        dir - The directory to list.
        array - The array of files and perhaps directories found.
        Returns:
        true for success, false for failure.
      • listDirectory

        public static boolean listDirectory​(java.lang.String dir,
                                            java.util.ArrayList<java.io.File> array,
                                            boolean includeDirectories)
        Gets a directory listing including all children and sub-directories.
        Parameters:
        dir - The directory to list.
        array - The array of files and perhaps directories found.
        includeDirectories - Flag to include directories if true, false for only files.
        Returns:
        true for success, false for failure.
      • listDirectory

        public static boolean listDirectory​(java.io.File dir,
                                            java.util.ArrayList<java.io.File> array)
        Gets a directory listing including all children and sub-directories. Only files are added.
        Parameters:
        dir - The directory to list.
        array - The array of files and perhaps directories found.
        Returns:
        true for success, false for failure.
      • listDirectory

        public static boolean listDirectory​(java.io.File dir,
                                            java.util.ArrayList<java.io.File> array,
                                            boolean includeDirectories)
        Gets a directory listing including all children and sub-directories.
        Parameters:
        dir - The directory to list.
        array - The array of files and perhaps directories found.
        includeDirectories - Flag to include directories if true, false for only files.
        Returns:
        true for success, false for failure.
      • deleteFileAndChildren

        public static boolean deleteFileAndChildren​(java.io.File dir)
        Deletes a file or directory along with all its children (in case of a directory).
        Returns:
        true for success, false for failure (some file/directory may remain, but as much as possible is deleted).
      • getFileExtension

        public static java.lang.String getFileExtension​(java.io.File file)
        Gets the extension of a file. The return value is the extension of the file without the last dot. This functions doesn't make a difference with the OS implementations "\" or "/", both are accepted!
        Parameters:
        file - the file.
        Returns:
        null when no file extension is found!
      • getFileExtension

        public static java.lang.String getFileExtension​(java.lang.String fileName)
        Gets the extension of a file. The return value is the extension of the file without the last dot. This functions doesn't make a difference with the OS implementations "\" or "/", both are accepted!
        Parameters:
        fileName - the file name.
        Returns:
        null when no file extension is found!
      • hasFileExtension

        public static boolean hasFileExtension​(java.io.File file,
                                               boolean caseSensitive,
                                               java.lang.String... extensions)
        Checks the extension of a file for a valid one with the ones specified in the list of extensions. The option "caseSensitive" can be set if required. This functions doesn't make a difference with the OS implementations "\" or "/", both are accepted!
        Parameters:
        file - the file.
        caseSensitive - if case sensitivity is used or not.
        extensions - a variable length of file extensions without the ".", e.g. "html","htm" for HTML files.
        Returns:
        true if the file has one of the file extensions, false otherwise.
      • hasFileExtension

        public static boolean hasFileExtension​(java.lang.String fileName,
                                               boolean caseSensitive,
                                               java.lang.String... extensions)
        Checks the extension of a file for a valid one with the ones specified in the list of extensions. The option "caseSensitive" can be set if required. This functions doesn't make a difference with the OS implementations "\" or "/", both are accepted!
        Parameters:
        fileName - the file name.
        caseSensitive - if case sensitivity is used or not.
        extensions - a variable length of file extensions without the ".", e.g. "html","htm" for HTML files.
        Returns:
        true if the file has one of the file extensions, false otherwise.
      • isJarOrZipFile

        public static boolean isJarOrZipFile​(java.lang.String fileName)
        Checks if a file is of Jar or Zip file type (i.e. has JAR or ZIP file extension, case insensitive).
      • isJarOrZipFile

        public static boolean isJarOrZipFile​(java.io.File file)
        Checks if a file is of Jar or Zip file type (i.e. has JAR or ZIP file extension, case insensitive).