[OFBiz] SVN: r7216 - trunk/base/src/base/org/ofbiz/base/util

jaz@svn.ofbiz.org jaz at svn.ofbiz.org
Thu Apr 6 13:53:15 CDT 2006


Author: jaz
Date: 2006-04-06 13:53:14 -0500 (Thu, 06 Apr 2006)
New Revision: 7216

Modified:
   trunk/base/src/base/org/ofbiz/base/util/FileUtil.java
Log:
added read text file method


Modified: trunk/base/src/base/org/ofbiz/base/util/FileUtil.java
===================================================================
--- trunk/base/src/base/org/ofbiz/base/util/FileUtil.java	2006-04-06 14:42:02 UTC (rev 7215)
+++ trunk/base/src/base/org/ofbiz/base/util/FileUtil.java	2006-04-06 18:53:14 UTC (rev 7216)
@@ -29,6 +29,9 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.BufferedReader;
 
 /**
  * File Utilities
@@ -45,7 +48,7 @@
         writeString(null, fileName, s);
     }
 
-    public static void writeString(String path, String name, String s) throws IOException {      
+    public static void writeString(String path, String name, String s) throws IOException {
         Writer out = getBufferedWriter(path, name);
 
         try {
@@ -96,4 +99,23 @@
 
         return fileName;
     }
+
+    public static StringBuffer readTextFile(String fileName, boolean newline) throws FileNotFoundException, IOException {
+        File file = new File(fileName);
+        if (!file.exists()) {
+            throw new FileNotFoundException();
+        }
+
+        StringBuffer buf = new StringBuffer();
+        BufferedReader in = new BufferedReader(new FileReader(file));
+        String str;
+        while ((str = in.readLine()) != null) {
+            buf.append(str);
+            if (newline) {
+                buf.append(System.getProperty("line.separator"));
+            }
+        }
+
+        return buf;
+    }
 }



More information about the Svn mailing list