Android File Read readTextFile(File file)

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

Description

read Text File

Declaration

public static String readTextFile(File file) throws IOException 

Method Source Code

//package com.java2s;

import java.io.*;

public class Main {
    public static String readTextFile(File file) throws IOException {
        String text = null;/*from  ww w.  j  a v a2 s .  c  o m*/
        InputStream is = null;
        if (null != file) {
            try {
                is = new FileInputStream(file);
                text = readTextInputStream(is);
                ;
            } finally {
                if (is != null) {
                    is.close();
                }
            }
        }
        return text;
    }

    public static String readTextInputStream(InputStream is)
            throws IOException {
        if (null == is)
            return null;
        StringBuffer strbuffer = new StringBuffer();
        String line;
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(is));
            while ((line = reader.readLine()) != null) {
                strbuffer.append(line).append("\r\n");
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
        return strbuffer.toString();
    }
}

Related

  1. readFileToString(String pathToFile)
  2. readFromFile(String filename)
  3. readInstallationFile(File installation)
  4. readStringFromFile(File file)
  5. readTemplate(String filePath)
  6. loadFile(String str)
  7. getFileContent(File file)
  8. LoadFile(String fileName, Resources resources)
  9. readFileToByteArray(String pathToFile)