From 2fd2de0c0ad74288ec2c1179a8a5befed7143ce1 Mon Sep 17 00:00:00 2001 From: "hyunsik.noh" Date: Wed, 28 Aug 2013 20:50:14 +0900 Subject: [PATCH] [Title]Add appendTextFile [Type] [Module]common [Priority] [CQ#] [Redmine#]10260 [Problem] [Cause] [Solution] Change-Id: Id4e5a8b3a4b52135c438df63542b9230c0e99964 --- .../src/org/tizen/common/util/FileUtil.java | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/org.tizen.common/src/org/tizen/common/util/FileUtil.java b/org.tizen.common/src/org/tizen/common/util/FileUtil.java index 2f6bc82..59478e1 100755 --- a/org.tizen.common/src/org/tizen/common/util/FileUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/FileUtil.java @@ -169,6 +169,26 @@ public class FileUtil { * @throws IOException If don't write file, it throws IOException */ public static boolean writeTextFile(File file, String text, String encoding) throws IOException { + return writeTextFile(file, text, encoding, false); + } + + /** + * Append text into given file + * + * @param file + * @param text Input context + * @param encoding If encoding is not set(null), then use system's default encoding. + * + * @return If file write success, return true. + * + * @throws IOException If don't write file, it throws IOException + */ + public static boolean appendTextFile(File file, String text, String encoding) throws IOException { + return writeTextFile(file, text, encoding, true); + } + + + private static boolean writeTextFile(File file, String text, String encoding, boolean doAppend) throws IOException { if (encoding == null) { // if encoding is not set then use default encoding encoding = System.getProperty("file.encoding"); } @@ -181,8 +201,10 @@ public class FileUtil { } BufferedWriter out = null; + FileOutputStream fileOut = new FileOutputStream(file, doAppend); + try { - out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding), BUFFER_SIZE); + out = new BufferedWriter(new OutputStreamWriter(fileOut, encoding), BUFFER_SIZE); out.write(text.toCharArray(), 0, text.length()); out.flush(); } finally { -- 2.7.4