diff --git a/src/main/java/org/auioc/mods/arnicalib/utils/java/FileUtils.java b/src/main/java/org/auioc/mods/arnicalib/utils/java/FileUtils.java index 5bbe4f02..517f875e 100644 --- a/src/main/java/org/auioc/mods/arnicalib/utils/java/FileUtils.java +++ b/src/main/java/org/auioc/mods/arnicalib/utils/java/FileUtils.java @@ -3,6 +3,7 @@ import static org.auioc.mods.arnicalib.ArnicaLib.LOGGER; import java.io.BufferedWriter; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.nio.charset.Charset; @@ -37,6 +38,21 @@ public static File getFile(String fileName) throws IOException { throw new IOException("Could not create parent directory of file \"" + file + "\""); } + /** + * Reads the contents of a file into a String using the UTF-8 charset. + * The file is always closed. + * + * @param file the file to read, must not be {@code null} + * @return the file contents, never {@code null} + * @throws NullPointerException if file is {@code null}. + * @throws FileNotFoundException if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading. + * @throws IOException if an I/O error occurs. + * @see org.apache.commons.io.FileUtils#readFileToString(File, Charset) + * @since 5.1.4 + */ + public static String readFileToString(final File file) throws IOException { + return readFileToString(file, Charset.forName("utf8")); + } /** * Writes a String to a file creating the file if it does not exist using the UTF-8 charset. @@ -44,6 +60,7 @@ public static File getFile(String fileName) throws IOException { * @param file the file to write * @param data the content to write to the file * @throws IOException in case of an I/O error + * @see org.apache.commons.io.FileUtils#writeStringToFile(File, String, Charset, boolean) * @since 5.1.4 */ public static void writeStringToFile(final File file, final String data) throws IOException {