Java BufferedReader Read readFile(String path)

Here you can find the source of readFile(String path)

Description

Reads file and stores into a string and returns it in one method

License

Apache License

Parameter

Parameter Description
path The directory or path to the text file

Return

str

Declaration

public static String readFile(String path) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Main {
    /**//w w w  .j  a  va 2s.c  o m
     * 
     * Reads file and stores into a string and returns it in one method
     * 
     * @see BufferedReader
     * 
     * @param path The directory or path to the text file
     * @return str
     */
    public static String readFile(String path) {
        String str = "";
        try {
            BufferedReader reader = new BufferedReader(new FileReader("path"));

            String tmp = "";

            while ((tmp = reader.readLine()) != null)
                str += "";

            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return str;
    }
}

Related

  1. readFile(String path)
  2. readFile(String path)
  3. readFile(String path)
  4. readFile(String path)
  5. readFile(String path)
  6. readFile(String path)
  7. readFile(String pathname)
  8. readFile(String sFileName_)
  9. readFile(String uri)