Android Text File Read readTextFile(String filePath)

Here you can find the source of readTextFile(String filePath)

Description

read Text File

Declaration

public static String readTextFile(String filePath) 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;
import java.io.File;

import java.io.FileReader;

public class Main {
    public static String readTextFile(String filePath) {
        File textFile = new File(filePath);
        BufferedReader in = null;
        String text = null;/*from  w  w w.  j ava  2s  . co  m*/
        StringBuilder allText = new StringBuilder("");

        try {
            in = new BufferedReader(new FileReader(textFile));
            while ((text = in.readLine()) != null) {
                allText.append(text).append("\n");
            }
        } catch (Exception e) {
            e.printStackTrace();

            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception ee) {
                ee.printStackTrace();
            }
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return allText.toString();
    }
}

Related

  1. readFull(String path)
  2. readLines(String file)
  3. readStringFromClasspath(String path, Class c)
  4. readStringFromFile(String fileName)
  5. readText(String path)
  6. readTextFile(String path)
  7. setFileResourceText(String path, String content)
  8. getContent(String file, String encodType)
  9. getString(File file)