Package io.github.astrapi69.file.read
Class ReadFileExtensions
java.lang.Object
io.github.astrapi69.file.read.ReadFileExtensions
The class
ReadFileExtensions
helps in reading files.-
Method Summary
Modifier and TypeMethodDescriptionstatic long
countAllLines
(File fileToCountTheLines) Counts all lines in the specified filestatic String
Reads the given file with UTF-8 encoding and returns the content as Stringstatic String
Reads the given file with the specified encoding and returns the content as Stringstatic Byte[]
getFilecontentAsByteObjectArray
(File tmpFile) Gets the file content as Byte array from the given filestatic byte[]
readFileToBytearray
(File file) Reads the given file to a byte arraystatic String
readHeadLine
(String inputFile) Reads the first line from the specified filestatic String
Reads a line at the specified index from the file, or null if the line does not existreadLinesInList
(File input) Reads all lines from the specified file into a listreadLinesInList
(File input, boolean trim) Reads every line from the File and puts them to the List.readLinesInList
(File input, Charset encoding) Reads every line from the File and puts them to the List.readLinesInList
(File input, Charset encoding, boolean trim) Reads every line from the File and puts them to the List.readLinesInList
(InputStream input) Reads every line from the given InputStream and puts them to the List.readLinesInList
(InputStream input, boolean trim) Reads every line from the given InputStream and puts them to the List.readLinesInList
(InputStream input, Charset encoding, boolean trim) Reads every line from the given InputStream and puts them to the List.static Properties
readPropertiesFromFile
(String filename) Reads properties from a properties filestatic byte[]
toByteArray
(File tmpFile) Reads file content into a byte arraystatic byte[]
toByteArray
(InputStream input) Get a byte array from the givenInputStream
.
-
Method Details
-
getFilecontentAsByteObjectArray
Gets the file content as Byte array from the given file- Parameters:
tmpFile
- the temporary file- Returns:
- the file content as Byte array object
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
readFileToBytearray
Reads the given file to a byte array- Parameters:
file
- the file to read- Returns:
- byte array of the file content or null
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
fromFile
Reads the given file with UTF-8 encoding and returns the content as String- Parameters:
file
- the file to read- Returns:
- String content from the file
- Throws:
IOException
- Signals that an I/O exception has occurred
-
fromFile
Reads the given file with the specified encoding and returns the content as String- Parameters:
file
- the file to readencoding
- the encoding to use- Returns:
- String content from the file
- Throws:
IOException
- Signals that an I/O exception has occurred
-
readHeadLine
Reads the first line from the specified file- Parameters:
inputFile
- the file path- Returns:
- first line from the file
- Throws:
FileNotFoundException
- is thrown if the given file is not found.IOException
- Signals that an I/O exception has occurred.
-
readLinesInList
Reads all lines from the specified file into a list- Parameters:
input
- the file to read- Returns:
- list of lines from the file
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
readLine
Reads a line at the specified index from the file, or null if the line does not exist- Parameters:
input
- the file to readindex
- The index of the line- Returns:
- The line or null if it does not exist
- Throws:
FileNotFoundException
- is thrown if the given file is not found.IOException
- Signals that an I/O exception has occurred.
-
readLinesInList
public static List<String> readLinesInList(File input, boolean trim) throws FileNotFoundException, IOException Reads every line from the File and puts them to the List.- Parameters:
input
- The File from where the input comes.trim
- the flag trim if the lines shell be trimed.- Returns:
- The List with all lines from the file.
- Throws:
FileNotFoundException
- is thrown if the given file is not found.IOException
- Signals that an I/O exception has occurred.
-
readLinesInList
public static List<String> readLinesInList(File input, Charset encoding) throws FileNotFoundException, IOException Reads every line from the File and puts them to the List.- Parameters:
input
- The File from where the input comes.encoding
- the encoding- Returns:
- The List with all lines from the file.
- Throws:
FileNotFoundException
- is thrown if the given file is not found.IOException
- When a io-problem occurs.
-
readLinesInList
public static List<String> readLinesInList(File input, Charset encoding, boolean trim) throws FileNotFoundException, IOException Reads every line from the File and puts them to the List.- Parameters:
input
- The File from where the input comes.encoding
- the charset for readtrim
- the flag trim if the lines shell be trimed.- Returns:
- The List with all lines from the file.
- Throws:
FileNotFoundException
- is thrown if the given file is not found.IOException
- When a io-problem occurs.
-
readLinesInList
Reads every line from the given InputStream and puts them to the List.- Parameters:
input
- The InputStream from where the input comes.- Returns:
- The List with all lines from the file.
- Throws:
IOException
- When a io-problem occurs.
-
readLinesInList
Reads every line from the given InputStream and puts them to the List.- Parameters:
input
- The InputStream from where the input comes.trim
- the flag trim if the lines shell be trimed.- Returns:
- The List with all lines from the file.
- Throws:
IOException
- When a io-problem occurs.
-
readLinesInList
public static List<String> readLinesInList(InputStream input, Charset encoding, boolean trim) throws IOException Reads every line from the given InputStream and puts them to the List.- Parameters:
input
- The InputStream from where the input comes.encoding
- the charset for readtrim
- the flag trim if the lines shell be trimed.- Returns:
- The List with all lines from the file.
- Throws:
IOException
- When a io-problem occurs.
-
readPropertiesFromFile
Reads properties from a properties file- Parameters:
filename
- the properties file path- Returns:
- Properties object or null if error occurs
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
toByteArray
Reads file content into a byte array- Parameters:
tmpFile
- the file to read- Returns:
- byte array of file content or null
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
toByteArray
Get a byte array from the givenInputStream
.- Parameters:
input
- TheInputStream
.- Returns:
- the a byte array.
- Throws:
IOException
- Signals that an I/O exception has occurred.NullPointerException
- if the input is null
-
countAllLines
Counts all lines in the specified file- Parameters:
fileToCountTheLines
- the file to count lines from- Returns:
- line count
- Throws:
IOException
- Signals that an I/O exception has occurred.
-