Module file.worker

Class ReadFileExtensions

java.lang.Object
io.github.astrapi69.file.read.ReadFileExtensions

public final class ReadFileExtensions extends Object
The class ReadFileExtensions helps you reading files.
  • Method Details

    • getFilecontentAsByteObjectArray

      public static Byte[] getFilecontentAsByteObjectArray(File tmpFile) throws IOException
      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

      public static byte[] readFileToBytearray(File file) throws IOException
      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

      public static String fromFile(File file) throws IOException
      This method reads the given file with the default UTF-8 encoding and returns the content as an String object
      Parameters:
      file - The file to read to an String object
      Returns:
      The String object from the given file
      Throws:
      IOException - Signals that an I/O exception has occurred
    • fromFile

      public static String fromFile(File file, Charset encoding) throws IOException
      This method reads the given file with the given encoding and returns the content as an String object
      Parameters:
      file - The file to read to an String object
      encoding - 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

      public static String readHeadLine(String inputFile) throws FileNotFoundException, IOException
      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

      public static List<String> readLinesInList(File input) throws FileNotFoundException, IOException
      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

      public static String readLine(File input, int index) throws FileNotFoundException, IOException
      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 comes
      index - 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 read
      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 - When a io-problem occurs.
    • readLinesInList

      public static List<String> readLinesInList(InputStream input) throws IOException
      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

      public static List<String> readLinesInList(InputStream input, 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.
      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 read
      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.
    • readPropertiesFromFile

      public static Properties readPropertiesFromFile(String filename) throws IOException
      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

      public static byte[] toByteArray(File tmpFile) throws IOException
      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

      public static byte[] toByteArray(InputStream input) throws IOException
      Get a byte array from the given InputStream.
      Parameters:
      input - The InputStream.
      Returns:
      the a byte array.
      Throws:
      IOException - Signals that an I/O exception has occurred.
      NullPointerException - if the input is null
    • countAllLines

      public static long countAllLines(File fileToCountTheLines) throws IOException
      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.