java.lang.Object
com.github.hypfvieh.util.FileIoUtil
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibunggetTextfileFromUrl(String _url) Retrives a text file from an given URL.getTextfileFromUrl(String _url, Charset _charset) Retrives a text file from an given URL and reads the content with the given charset.getTextfileFromUrl(String _url, Charset _charset, boolean _silent) static StringguessLineTerminatorOfFile(String _file) Tries to find the line termination character(s) of the given file.static PropertiesloadPropertiesFromClasspath(String _propertiesFile) Loads the contents of a properties file located in the Java classpath into aPropertiesobject.static booleanloadPropertiesFromClasspath(String _propertiesFile, Properties _properties) Same asloadPropertiesFromClasspath(String)but does not throw checked exception.static InputStreamopenInputStreamForFile(String _fileNameWithPath, SearchOrder... _searchOrder) Tries to find _fileNameWithPath in either classpath, systempath or absolute path and opens anInputStreamfor it.readFileFrom(String _fileName, Charset _charset, SearchOrder... _searchOrder) Read a file from different sources depending on _searchOrder.static StringreadFileFromClassPath(String _fileName) Reads a file from classpath to String.readFileFromClassPathAsList(String _fileName) Reads a file from classpath to a list of String using default charset and log any exception.readFileFromClassPathAsList(String _fileName, Charset _charset, boolean _silent) Reads a file from classpath to a list of String with the given charset.readFileToList(File _file) Reads a file to a List<String> (each line is one entry in list).readFileToList(String _fileName) Reads a file to a List<String> (each line is one entry in list).static StringreadFileToString(File _file) static StringreadFileToString(String _file) Reads a file and returns it's content as string.static PropertiesreadProperties(File _file) Trys to read a properties file.static PropertiesreadProperties(InputStream _stream) Tries to read a properties file from an inputstream.static booleanreadPropertiesBoolean(Properties _props, String _property) Reads a property as boolean from an properties object.static PropertiesreadPropertiesFromFile(String _fileName, Properties _props) Read properties from given filename (returns emptyPropertiesobject on failure).static StringreadStringFromResources(InputStream _stream, String _charset) Read a Resource-file (eg.readTextFileFromStream(InputStream _input, Charset _charset, boolean _silent) Reads a text file from givenInputStreamusing the givenCharset.static booleanwriteProperties(File _file, Properties _props) Writes a properties Object to file.static booleanwriteProperties(String _propertiesFile, Properties _props) Write a properties object to a given file (will overwrite existing files!).static booleanwriteTextFile(String _fileName, String _fileContent, boolean _append) Write String to file with the java default charset (usually UTF-8).static booleanwriteTextFile(String _fileName, String _fileContent, Charset _charset, boolean _append) Write String to file with the given charset.
-
Methodendetails
-
readProperties
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
Tries to read a properties file from an inputstream.- Parameter:
_stream-- Gibt zurück:
- properties object/null
-
readPropertiesFromFile
Read properties from given filename (returns emptyPropertiesobject 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:
Propertiesobject
-
writeProperties
Writes a properties Object to file. Returns true on success, false otherwise.- Parameter:
_file-_props-- Gibt zurück:
- true on success, false otherwise
-
writeProperties
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
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
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
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
- 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 givenInputStreamusing the givenCharset.- 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
Reads a file and returns it's content as string.- Parameter:
_file-- Gibt zurück:
-
readFileToList
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
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
-
readStringFromResources
Read a Resource-file (eg. Text) to String.- Parameter:
_stream-_charset-- Gibt zurück:
- the file as string, or null on error
-
loadPropertiesFromClasspath
Loads the contents of a properties file located in the Java classpath into aPropertiesobject.- 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
Same asloadPropertiesFromClasspath(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
Reads a file from classpath to String.- Parameter:
_fileName-- Gibt zurück:
- file contents as String or null
-
readFileFromClassPathAsList
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
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 anInputStreamfor it. Search order is specified bySearchOrdervarargs.- Parameter:
_fileNameWithPath-_searchOrder-- Gibt zurück:
- InputStream for the file or null if file could not be found
-
guessLineTerminatorOfFile
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
-