Android File to String Read readFile(String path)

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

Description

read File

Declaration

public static String readFile(String path) 

Method Source Code

//package com.java2s;

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.InputStreamReader;

public class Main {
    public static String readFile(String path) {
        StringBuffer str = new StringBuffer("");
        try {/*from   ww w  .ja  v  a2s. c  om*/
            InputStreamReader ir = new InputStreamReader(
                    new FileInputStream(path), "UTF8");
            BufferedReader br = new BufferedReader(ir);
            String data = br.readLine();

            while (data != null) {
                str.append(data);
                data = br.readLine();
            }
            br.close();
            ir.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return str.toString();
    }
}

Related

  1. getStringArrayFromFile(File inputFile)
  2. getStringFromFile(File inputFile)
  3. fromFile(File f)
  4. readFileOfList(String path)