Java File Content Read getFileContent(File file)

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

Description

Method to retrive the content of a file in a String

License

Open Source License

Parameter

Parameter Description
file a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static String getFileContent(File file) throws IOException 

Method Source Code

//package com.java2s;
/**/* w  w  w  .j a  v a 2  s  .com*/
 *  This file is part of LogiSima (http://www.logisima.com).
 *
 *  maven-testrunner-plugin is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  maven-testrunner-plugin is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with maven-testrunner-plugin. If not, see <http://www.gnu.org/licenses/>.
 *  
 *  @author Beno?t Simard
 *  @See https://github.com/sim51/maven-testrunner-plugin
 */

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

public class Main {
    /**
     * Method to retrive the content of a file in a <code>String</code>
     * 
     * @param file
     * @return
     * @throws IOException
     */
    public static String getFileContent(File file) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader(file));
        String content = "";
        String strLine;
        while ((strLine = br.readLine()) != null) {
            content += strLine + "\n";
        }
        return content;
    }
}

Related

  1. getFileContent(File file)
  2. getFileContent(File file)
  3. getFileContent(File file)
  4. getFileContent(File file)
  5. getFileContent(File file)
  6. getFileContent(File file)
  7. getFileContent(String fileName)
  8. getFileContent(String fileName)
  9. getFileContent(String fileName)