Java BufferedReader Read readFile(File file)

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

Description

Read file into string

License

BSD License

Declaration

public static String readFile(File file) throws IOException 

Method Source Code

//package com.java2s;
/***//www . j ava2 s .c  o m
 * Copyright (C) 2010 Johan Henriksson
 * This code is under the Endrov / BSD license. See www.endrov.net
 * for the full text and how to cite.
 */

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

public class Main {
    /**
     * Read file into string
     */
    public static String readFile(File file) throws IOException {
        StringBuffer bf = new StringBuffer();
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line;
        while ((line = br.readLine()) != null) {
            bf.append(line);
            bf.append("\n");
        }
        //TODO: should read file exactly as is. do not use readline!
        br.close();
        return bf.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)