From: Svjatoslav Agejenko Date: Sat, 3 Jan 2015 10:07:52 +0000 (+0200) Subject: added: String getFileContentsAsString(final File file) X-Git-Tag: svjatoslavcommons-1.8~89 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=85bd29620c59ea7f843a46691516a316358202ab;p=svjatoslav_commons.git added: String getFileContentsAsString(final File file) --- diff --git a/src/main/java/eu/svjatoslav/commons/file/IOHelper.java b/src/main/java/eu/svjatoslav/commons/file/IOHelper.java index 1cc7c02..46abaa5 100755 --- a/src/main/java/eu/svjatoslav/commons/file/IOHelper.java +++ b/src/main/java/eu/svjatoslav/commons/file/IOHelper.java @@ -1,7 +1,7 @@ /* * Svjatoslav Commons - shared library of common functionality. * Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. @@ -14,6 +14,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.UnsupportedEncodingException; public class IOHelper { @@ -49,11 +50,20 @@ public class IOHelper { return result; } + public static String getFileContentsAsString(final File file) + throws FileNotFoundException, IOException { + try { + return new String(getFileContents(file), "UTF-8"); + } catch (final UnsupportedEncodingException exception) { + throw new RuntimeException(exception); + } + } + /** * Compares new file content with old file content. If content in equal, * then leaves file as-is. If content differs, then overrides file with the * new content. - * + * * @return true if file was overwritten. */ public static boolean overwriteFileIfContentDiffers(final File file,