Java BufferedReader Read readFile(File from)

Here you can find the source of readFile(File from)

Description

Read the contents of a file into a StringBuffer

License

Open Source License

Declaration

public static StringBuffer readFile(File from) throws IOException 

Method Source Code

//package com.java2s;
/**/*from  www . j a  v  a  2  s .co  m*/
 * Util.java
 * @author John Green
 * 27-Oct-2002
 * www.joanju.com
 * 
 * Copyright (c) 2002 Joanju Limited.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 */

import java.io.*;

public class Main {
    /** Read the contents of a file into a StringBuffer */
    public static StringBuffer readFile(File from) throws IOException {
        BufferedReader in = new BufferedReader(new FileReader(from));
        StringWriter sWriter = new StringWriter();
        BufferedWriter out = new BufferedWriter(sWriter);
        int c;
        while ((c = in.read()) != -1)
            out.write(c);
        in.close();
        out.close();
        return sWriter.getBuffer();
    }
}

Related

  1. readFile(File file)
  2. readFile(File file)
  3. readFile(File file, boolean useSystemLineSeparator)
  4. readFile(File file, int header)
  5. readFile(File filename)
  6. readFile(File in)
  7. readFile(File inputFile)
  8. readFile(File location)
  9. readFile(File path)