From 85bd29620c59ea7f843a46691516a316358202ab Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sat, 3 Jan 2015 12:07:52 +0200 Subject: [PATCH] added: String getFileContentsAsString(final File file) --- .../java/eu/svjatoslav/commons/file/IOHelper.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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, -- 2.20.1