Class FilesUtility

java.lang.Object
com.yetnt.utils.io.FilesUtility

public class FilesUtility extends Object
  • Constructor Details

    • FilesUtility

      public FilesUtility()
  • Method Details

    • readFromFile

      public static void readFromFile(String path, Consumer<Scanner> consumer) throws IOException
      Reads the content of a file and processes it using the provided consumer. This method uses UTF-8 as the default character set.
      Parameters:
      path - The path to the file to be read.
      consumer - A Consumer that processes the Scanner object for the file content.
      Throws:
      IOException
    • readFromFile

      public static void readFromFile(String path, Consumer<Scanner> consumer, Charset csn) throws IOException
      Reads the content of a file and processes it using the provided consumer.
      Parameters:
      path - The path to the file to be read.
      consumer - A Consumer that processes the Scanner object for the file content.
      csn - The character set to use for reading the file. If null, UTF-8 is used.
      Throws:
      IOException
    • writeToFile

      public static void writeToFile(String path, String name, Consumer<PrintWriter> consumer) throws IOException
      Writes content to a file using the provided consumer. This method uses UTF-8 as the default character set.
      Parameters:
      path - The directory path where the file will be created.
      name - The name of the file to be created.
      consumer - A Consumer that writes content to the PrintWriter object.
      Throws:
      IOException
    • writeToFile

      public static void writeToFile(String path, String name, Consumer<PrintWriter> consumer, Charset csn) throws IOException
      Writes content to a file using the provided consumer and character set.
      Parameters:
      path - The directory path where the file will be created.
      name - The name of the file to be created.
      consumer - A Consumer that writes content to the PrintWriter object.
      csn - The character set to use for writing the file. If null, UTF-8 is used.
      Throws:
      IOException
    • fileChooser

      public static File fileChooser(Consumer<JFileChooser> chooserConfigure, JFrame frameParent)
      Shows a file chooser dialog and returns the selected file's absolute path.
      Parameters:
      chooserConfigure - A consumer that configures the file chooser.
      Returns:
      The absolute path of the selected file, or null if no file is selected.
    • folderChooser

      public static File folderChooser(JFrame frameParent)
      Shows a folder chooser dialog and returns the selected folder's absolute path.
      Returns:
      The absolute path of the selected folder, or null if no folder is selected.
    • writeBinary

      public static void writeBinary(String path, String name, Consumer<DataOutputStream> consumer) throws IOException
      Throws:
      IOException
    • readBinary

      public static void readBinary(String path, String name, Consumer<DataInputStream> consumer) throws IOException
      Throws:
      IOException