Klasse FileIoUtil

java.lang.Object
com.github.hypfvieh.util.FileIoUtil

public final class FileIoUtil extends Object
  • Methodendetails

    • readProperties

      public static Properties readProperties(File _file)
      Trys to read a properties file. Returns null if properties file could not be loaded
      Parameter:
      _file -
      Gibt zurück:
      Properties Object or null
    • readProperties

      public static Properties readProperties(InputStream _stream)
      Tries to read a properties file from an inputstream.
      Parameter:
      _stream -
      Gibt zurück:
      properties object/null
    • readPropertiesFromFile

      public static Properties readPropertiesFromFile(String _fileName, Properties _props)
      Read properties from given filename (returns empty Properties object on failure).
      Parameter:
      _fileName - The properties file to read
      _props - optional properties object, if null a new object created in the method
      Gibt zurück:
      Properties object
    • writeProperties

      public static boolean writeProperties(File _file, Properties _props)
      Writes a properties Object to file. Returns true on success, false otherwise.
      Parameter:
      _file -
      _props -
      Gibt zurück:
      true on success, false otherwise
    • writeProperties

      public static boolean writeProperties(String _propertiesFile, Properties _props)
      Write a properties object to a given file (will overwrite existing files!).
      Parameter:
      _propertiesFile - - The filename you want to use
      _props - - The properties to save
      Gibt zurück:
      boolean true on success, false on exception
    • readPropertiesBoolean

      public static boolean readPropertiesBoolean(Properties _props, String _property)
      Reads a property as boolean from an properties object. Returns true if read property matches 1, yes, true, enabled, on, y
      Parameter:
      _props -
      _property -
      Gibt zurück:
    • getTextfileFromUrl

      public static List<String> getTextfileFromUrl(String _url)
      Retrives a text file from an given URL. Url could be remote (like http://) or local (file://) If protocol is not specified by "protocol://" (like "http://" or "file://"), "file://" is assumed.
      Parameter:
      _url -
      Gibt zurück:
      fileContent as List or null if file is empty or an error occoured
    • getTextfileFromUrl

      public static List<String> getTextfileFromUrl(String _url, Charset _charset)
      Retrives a text file from an given URL and reads the content with the given charset. Url could be remote (like http://) or local (file://) If protocol is not specified by "protocol://" (like "http://" or "file://"), "file://" is assumed.
      Parameter:
      _url -
      _charset -
      Gibt zurück:
      fileContent as List or null if file is empty or an error occurred.
    • getTextfileFromUrl

      public static List<String> getTextfileFromUrl(String _url, Charset _charset, boolean _silent)
      Parameter:
      _url -
      _charset -
      _silent - true to not log exceptions, false otherwise
      Gibt zurück:
      list of string or null on error
      Siehe auch:
    • readTextFileFromStream

      public static List<String> readTextFileFromStream(InputStream _input, Charset _charset, boolean _silent)
      Reads a text file from given InputStream using the given Charset.
      Parameter:
      _input - stream to read
      _charset - charset to use
      _silent - true to disable exception logging, false otherwise
      Gibt zurück:
      List of string or null on error
    • readFileToString

      public static String readFileToString(String _file)
      Reads a file and returns it's content as string.
      Parameter:
      _file -
      Gibt zurück:
    • readFileToList

      public static List<String> readFileToList(File _file)
      Reads a file to a List<String> (each line is one entry in list). Line endings (line feed/carriage return) are NOT removed!
      Parameter:
      _file -
      Gibt zurück:
    • readFileToList

      public static List<String> readFileToList(String _fileName)
      Reads a file to a List<String> (each line is one entry in list). Line endings (line feed/carriage return) are NOT removed!
      Parameter:
      _fileName -
      Gibt zurück:
    • readFileToString

      public static String readFileToString(File _file)
    • readStringFromResources

      public static String readStringFromResources(InputStream _stream, String _charset)
      Read a Resource-file (eg. Text) to String.
      Parameter:
      _stream -
      _charset -
      Gibt zurück:
      the file as string, or null on error
    • loadPropertiesFromClasspath

      public static Properties loadPropertiesFromClasspath(String _propertiesFile) throws IOException
      Loads the contents of a properties file located in the Java classpath into a Properties object.
      Parameter:
      _propertiesFile - properties file located in Java classpath
      Gibt zurück:
      properties object
      Löst aus:
      IOException - if file not found or loading fails for other I/O reasons
    • loadPropertiesFromClasspath

      public static boolean loadPropertiesFromClasspath(String _propertiesFile, Properties _properties)
      Same as loadPropertiesFromClasspath(String) but does not throw checked exception. The returned boolean indicates if loading was successful. Read properties are stored in the given properties object (should never be null!).
      Parameter:
      _propertiesFile -
      _properties -
      Gibt zurück:
      true if properties could be loaded, false otherwise
    • readFileFromClassPath

      public static String readFileFromClassPath(String _fileName)
      Reads a file from classpath to String.
      Parameter:
      _fileName -
      Gibt zurück:
      file contents as String or null
    • readFileFromClassPathAsList

      public static List<String> readFileFromClassPathAsList(String _fileName)
      Reads a file from classpath to a list of String using default charset and log any exception.
      Parameter:
      _fileName -
      Gibt zurück:
      file contents or empty list
    • readFileFromClassPathAsList

      public static List<String> readFileFromClassPathAsList(String _fileName, Charset _charset, boolean _silent)
      Reads a file from classpath to a list of String with the given charset. Will optionally suppress any exception logging.
      Parameter:
      _fileName - file to read
      _charset - charset to use for reading
      _silent - true to suppress error logging, false otherwise
      Gibt zurück:
      file contents or null on exception
    • writeTextFile

      public static boolean writeTextFile(String _fileName, String _fileContent, Charset _charset, boolean _append)
      Write String to file with the given charset. Optionally appends the data to the file.
      Parameter:
      _fileName - the file to write
      _fileContent - the content to write
      _charset - the charset to use
      _append - append content to file, if false file will be overwritten if existing
      Gibt zurück:
      true on successful write, false otherwise
    • writeTextFile

      public static boolean writeTextFile(String _fileName, String _fileContent, boolean _append)
      Write String to file with the java default charset (usually UTF-8). Optionally appends the data to the file.
      Parameter:
      _fileName - the file to write
      _fileContent - the content to write
      _append - append content to file, if false file will be overwritten if existing
      Gibt zurück:
      true on successful write, false otherwise
    • readFileFrom

      public static List<String> readFileFrom(String _fileName, Charset _charset, SearchOrder... _searchOrder)
      Read a file from different sources depending on _searchOrder. Will return the first successfully read file which can be loaded either from custom path, classpath or system path.
      Parameter:
      _fileName - file to read
      _charset - charset used for reading
      _searchOrder - search order
      Gibt zurück:
      List of String with file content or null if file could not be found
    • openInputStreamForFile

      public static InputStream openInputStreamForFile(String _fileNameWithPath, SearchOrder... _searchOrder)
      Tries to find _fileNameWithPath in either classpath, systempath or absolute path and opens an InputStream for it. Search order is specified by SearchOrder varargs.
      Parameter:
      _fileNameWithPath -
      _searchOrder -
      Gibt zurück:
      InputStream for the file or null if file could not be found
    • guessLineTerminatorOfFile

      public static String guessLineTerminatorOfFile(String _file)
      Tries to find the line termination character(s) of the given file. Only useful for files with text content!
      Parameter:
      _file -
      Gibt zurück:
      never null, will return system default line terminator on any error