Java BufferedReader Read readFile(File file)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(File file) 

Method Source Code


//package com.java2s;
/*/*from  www.  j a  v a 2 s  . c  o m*/
 * Copyright (c) 2005 IBM Corporation and others.
 * 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
 *
 * Contributors:
 *   IBM - initial API and implementation
 *
 * $Id: BuildUtil.java,v 1.3 2007/02/22 08:40:26 asobolev Exp $
 */

import java.io.BufferedReader;

import java.io.File;
import java.io.FileReader;

import java.io.IOException;

public class Main {
    public static String readFile(File file) {
        StringBuffer stringBuffer = new StringBuffer();

        try {
            BufferedReader in = new BufferedReader(new FileReader(file));

            try {
                char[] buffer = new char[1024];
                int size = 0;
                while ((size = in.read(buffer)) > -1) {
                    stringBuffer.append(buffer, 0, size);
                }
            } finally {
                if (in != null) {
                    in.close();
                }
            }
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
        return stringBuffer.toString();
    }
}

Related

  1. readFile(File file)
  2. readFile(File file)
  3. readFile(File file)
  4. readFile(File file)
  5. readFile(File file)
  6. readFile(File file)
  7. readFile(File file)
  8. readFile(File file)
  9. readFile(File file)