Index: FileUtils.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons-sandbox/io/src/java/org/apache/commons/io/FileUtils.java,v
retrieving revision 1.5
diff -u -r1.5 FileUtils.java
--- FileUtils.java	28 Jan 2002 10:03:11 -0000	1.5
+++ FileUtils.java	22 Feb 2002 18:43:23 -0000
@@ -59,6 +59,7 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.util.Vector;
 
 
@@ -72,6 +73,7 @@
  * @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
  * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
  * @author <a href="mailto:Christoph.Reck@dlr.de">Christoph.Reck</a>
+ * @author <a href="mailto:stevencaswell@yahoo.com">Steven Caswell</a>
  * @version $Id: FileUtils.java,v 1.5 2002/01/28 10:03:11 sanders Exp $
  */
 public class FileUtils {
@@ -192,8 +194,14 @@
      * @param fileName The name of the file to read.
      * @return The file contents or null if read failed.
      */
-    public static String fileRead(String fileName) throws Exception {
-        StringBuffer buf = new StringBuffer();
+    public static StringBuffer fileRead(String fileName) throws Exception {
+        File file = new File(fileName);
+        int estimatedSize = new Long(file.length()).intValue();
+        if(estimatedSize < 512)
+        {
+            estimatedSize = 512;
+        }
+        StringBuffer buf = new StringBuffer(estimatedSize);
 
         FileInputStream in = new FileInputStream(fileName);
 
@@ -206,11 +214,12 @@
 
         in.close();
 
-        return buf.toString();
+        return buf;
     }
 
     /**
-     * Writes data to a file. The file will be created if it does not exist.
+     * Writes data to a file. The file will be created if it does not exist.  The file will be
+     * overwritten if it exists.
      *
      * @param fileName The name of the file to write.
      * @param data The content to write to the file.
@@ -221,6 +230,87 @@
         out.close();
     }
 
+    /**
+     * Writes data to a file. The file will be created if it does not exist.  The file will be
+     * overwritten if it exists.
+     *
+     * @param fileName The name of the file to write.
+     * @param data The content to write to the file.
+     */
+    public static void fileWrite(String fileName, byte[] data) throws Exception {
+        FileOutputStream out = new FileOutputStream(fileName);
+        out.write(data);
+        out.close();
+    }
+
+    /**
+     * Copy the contents of a file to another file.
+     *
+     * @param sourceFileName The name of the file to be copied.
+     * @param targetFileName The name of the file to be created.
+     * @param overwrite Indicates whether the target file should be overwritten if it exists.
+     * @return true if the file was copied.
+     */
+    public static boolean fileCopy(String sourceFileName, String targetFileName, boolean overwrite) throws IOException {
+        return fileCopy(getFile(sourceFileName), getFile(targetFileName), overwrite);
+//        return fileCopy(getFile("src/test/org/apache/commons/io/TestAll.java"), getFile(targetFileName), overwrite);
+    }
+    
+    /**
+     * Copy the contents of a file to another file.
+     *
+     * @param sourceFile The file to be copied.
+     * @param targetFile The file to be created.
+     * @param overwrite Indicates whether the target file should be overwritten if it exists.
+     * @return true if the file was copied.
+     */
+    public static boolean fileCopy(File sourceFile, File targetFile, boolean overwrite) throws IOException {
+        File writeFile = null;
+        byte buf[] = new byte[512];
+
+        // If the target file spec is a relative path with no file name,
+        // use the source file name
+        if( targetFile.isDirectory() == true &&
+            targetFile.isFile() == false ) {
+            writeFile = new File( targetFile.getCanonicalPath(), sourceFile.getName());
+        }
+        else {
+            writeFile = targetFile;
+        }
+
+        // If overwrite is false, check to see if the targetFile exists
+        // If it does exists, return false
+        if( overwrite == false) {
+            if( writeFile.isFile()) {
+                // File exists, return false
+                return false;
+            }
+        }
+
+        // Copy the file
+        FileInputStream fis = null;
+        FileOutputStream fos = null;
+        try {
+            fis = new FileInputStream(sourceFile.getAbsoluteFile());
+            fos = new FileOutputStream(writeFile.getAbsoluteFile());
+            int count = 0;
+            while ((count = fis.read(buf)) > 0) {  // blocking read
+                fos.write(buf, 0, count);
+            }
+        }
+        finally {
+            if (fos != null) {
+                fos.close();
+            }
+            if (fis != null) {
+                try {
+                    fis.close();
+                } catch (Exception e) {}
+            }
+        }
+        return true;
+    }
+    
     /**
      * Deletes a file.
      *
