java.lang.Object
io.github.astrapi69.file.read.ReadFileExtensions
The class
ReadFileExtensions
helps you reading files.-
Method Summary
Modifier and TypeMethodDescriptionstatic long
countAllLines
(File fileToCountTheLines) Count all lines from the given filestatic String
This method reads the given file with the default UTF-8 encoding and returns the content as anString
objectstatic String
This method reads the given file with the given encoding and returns the content as anString
objectstatic Byte[]
getFilecontentAsByteObjectArray
(File tmpFile) Get a Byte array from the given file.static byte[]
readFileToBytearray
(File file) Get a byte array from the given file.static String
readHeadLine
(String inputFile) The Method readHeadLine() opens the File and reads the first line from the file.static String
Read a line from the given index in the given File and return it, if index greater than null is returnedreadLinesInList
(File input) Reads every line from the File and puts them to the List.readLinesInList
(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) The Method readFromFile(String) reads from the properties-file all Properties and saves them into a Properties-Object.static byte[]
toByteArray
(File tmpFile) Get a byte array from the given file.static byte[]
toByteArray
(InputStream input) Get a byte array from the givenInputStream
.
-
Method Details
-
getFilecontentAsByteObjectArray
Get a Byte array from the given file.- Parameters:
tmpFile
- the tmp file- Returns:
- the filecontent as Byte array object.
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
readFileToBytearray
Get a byte array from the given file.- Parameters:
file
- The file.- Returns:
- Returns a byte array or null.
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
fromFile
This method reads the given file with the default UTF-8 encoding and returns the content as anString
object- Parameters:
file
- The file to read to anString
object- Returns:
- The
String
object from the given file - Throws:
IOException
- Signals that an I/O exception has occurred
-
fromFile
This method reads the given file with the given encoding and returns the content as anString
object- Parameters:
file
- The file to read to anString
objectencoding
- the encoding for reading the given file- Returns:
- The
String
object from the given file - Throws:
IOException
- Signals that an I/O exception has occurred
-
readHeadLine
The Method readHeadLine() opens the File and reads the first line from the file.- Parameters:
inputFile
- The Path to the File and name from the file from where we read.- Returns:
- The 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 every line from the File and puts them to the List.- Parameters:
input
- The File from where the input comes.- 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.
-
readLine
Read a line from the given index in the given File and return it, if index greater than null is returned- Parameters:
input
- The File from where the input comesindex
- 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
The Method readFromFile(String) reads from the properties-file all Properties and saves them into a Properties-Object.- Parameters:
filename
- The Filename from the Properties-file.- Returns:
- The Properties or null if an error occurs.
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
toByteArray
Get a byte array from the given file.- Parameters:
tmpFile
- The file.- Returns:
- Returns a byte array 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
Count all lines from the given file- Parameters:
fileToCountTheLines
- The File to count the lines- Returns:
- the number of the lines from the given file
- Throws:
IOException
- Signals that an I/O exception has occurred.
-