public final class FileIoUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static List<String> |
getTextfileFromUrl(String _url)
Retrives a text file from an given URL.
|
static List<String> |
getTextfileFromUrl(String _url,
Charset _charset)
Retrives a text file from an given URL and reads the content with the given charset.
|
static List<String> |
getTextfileFromUrl(String _url,
Charset _charset,
boolean _silent) |
static Properties |
loadPropertiesFromClasspath(String _propertiesFile)
Loads the contents of a properties file located in the Java classpath
into a
Properties object. |
static boolean |
loadPropertiesFromClasspath(String _propertiesFile,
Properties _properties)
Same as
loadPropertiesFromClasspath(String) but does not throw checked exception. |
static InputStream |
openInputStreamForFile(String _fileNameWithPath,
SearchOrder... _searchOrder)
Tries to find _fileNameWithPath in either classpath, systempath or absolute path and opens an
InputStream for it. |
static List<String> |
readFileFrom(String _fileName,
Charset _charset,
SearchOrder... _searchOrder)
Read a file from different sources depending on _searchOrder.
|
static String |
readFileFromClassPath(String _fileName)
Reads a file from classpath to String.
|
static List<String> |
readFileFromClassPathAsList(String _fileName)
Reads a file from classpath to a list of String using default charset and log any exception.
|
static List<String> |
readFileFromClassPathAsList(String _fileName,
Charset _charset,
boolean _silent)
Reads a file from classpath to a list of String with the given charset.
|
static List<String> |
readFileToList(File _file)
Reads a file to a List<String> (each line is one entry in list).
|
static List<String> |
readFileToList(String _fileName)
Reads a file to a List<String> (each line is one entry in list).
|
static String |
readFileToString(File _file) |
static String |
readFileToString(String _url)
Reads a file and returns it's content as string.
|
static Properties |
readProperties(File _file)
Trys to read a properties file.
|
static Properties |
readProperties(InputStream _stream)
Tries to read a properties file from an inputstream.
|
static boolean |
readPropertiesBoolean(Properties _props,
String _property)
Reads a property as boolean from an properties object.
|
static Properties |
readPropertiesFromFile(String _fileName,
Properties _props)
Read properties from given filename
(returns empty
Properties object on failure). |
static String |
readStringFromResources(InputStream _stream,
String _charset)
Read a Resource-file (eg.
|
static List<String> |
readTextFileFromStream(InputStream _input,
Charset _charset,
boolean _silent)
Reads a text file from given
InputStream using the given Charset. |
static boolean |
writeProperties(File _file,
Properties _props)
Writes a properties Object to file.
|
static boolean |
writeProperties(String _propertiesFile,
Properties _props)
Write a properties object to a given file
(will overwrite existing files!).
|
static boolean |
writeTextFile(String _fileName,
String _fileContent,
boolean _append)
Write String to file with the java default charset (usually UTF-8).
|
static boolean |
writeTextFile(String _fileName,
String _fileContent,
Charset _charset,
boolean _append)
Write String to file with the given charset.
|
public static Properties readProperties(File _file)
_file - public static Properties readProperties(InputStream _stream)
_stream - public static Properties readPropertiesFromFile(String _fileName, Properties _props)
Properties object on failure)._fileName - The properties file to read_props - optional properties object, if null a new object created in the methodProperties objectpublic static boolean writeProperties(File _file, Properties _props)
_file - _props - public static boolean writeProperties(String _propertiesFile, Properties _props)
_propertiesFile - - The filename you want to use_props - - The properties to savepublic static boolean readPropertiesBoolean(Properties _props, String _property)
_props - _property - public static List<String> getTextfileFromUrl(String _url)
_url - public static List<String> getTextfileFromUrl(String _url, Charset _charset)
_url - _charset - public static List<String> getTextfileFromUrl(String _url, Charset _charset, boolean _silent)
_url - _charset - _silent - true to not log exceptions, false otherwisegetTextfileFromUrl(String, Charset)public static List<String> readTextFileFromStream(InputStream _input, Charset _charset, boolean _silent)
InputStream using the given Charset._input - stream to read_charset - charset to use_silent - true to disable exception logging, false otherwisepublic static String readFileToString(String _url)
_url - public static List<String> readFileToList(File _file)
_file - public static List<String> readFileToList(String _fileName)
_fileName - public static String readStringFromResources(InputStream _stream, String _charset)
_stream - _charset - public static Properties loadPropertiesFromClasspath(String _propertiesFile) throws IOException
Properties object._propertiesFile - properties file located in Java classpathIOException - if file not found or loading fails for other I/O reasonspublic static boolean loadPropertiesFromClasspath(String _propertiesFile, Properties _properties)
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!)._propertiesFile - _properties - public static String readFileFromClassPath(String _fileName)
_fileName - public static List<String> readFileFromClassPathAsList(String _fileName)
_fileName - public static List<String> readFileFromClassPathAsList(String _fileName, Charset _charset, boolean _silent)
_fileName - file to read_charset - charset to use for reading_silent - true to suppress error logging, false otherwisepublic static boolean writeTextFile(String _fileName, String _fileContent, Charset _charset, boolean _append)
_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 existingpublic static boolean writeTextFile(String _fileName, String _fileContent, boolean _append)
_fileName - the file to write_fileContent - the content to write_append - append content to file, if false file will be overwritten if existingpublic static List<String> readFileFrom(String _fileName, Charset _charset, SearchOrder... _searchOrder)
_fileName - file to read_charset - charset used for reading_searchOrder - search orderpublic static InputStream openInputStreamForFile(String _fileNameWithPath, SearchOrder... _searchOrder)
InputStream for it.
Search order is specified by SearchOrder varargs._fileNameWithPath - _searchOrder - Copyright © 2018. All rights reserved.