Package com.yetnt.utils.io
Class FilesUtility
java.lang.Object
com.yetnt.utils.io.FilesUtility
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FilefileChooser(Consumer<JFileChooser> chooserConfigure, JFrame frameParent) Shows a file chooser dialog and returns the selected file's absolute path.static FilefolderChooser(JFrame frameParent) Shows a folder chooser dialog and returns the selected folder's absolute path.static voidreadBinary(String path, String name, Consumer<DataInputStream> consumer) static voidreadFromFile(String path, Consumer<Scanner> consumer) Reads the content of a file and processes it using the provided consumer.static voidreadFromFile(String path, Consumer<Scanner> consumer, Charset csn) Reads the content of a file and processes it using the provided consumer.static voidwriteBinary(String path, String name, Consumer<DataOutputStream> consumer) static voidwriteToFile(String path, String name, Consumer<PrintWriter> consumer) Writes content to a file using the provided consumer.static voidwriteToFile(String path, String name, Consumer<PrintWriter> consumer, Charset csn) Writes content to a file using the provided consumer and character set.
-
Constructor Details
-
FilesUtility
public FilesUtility()
-
-
Method Details
-
readFromFile
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
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
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
-