Android Text File Read readText(String path)

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

Description

read Text

License

Apache License

Declaration

public static String readText(String path) throws IOException 

Method Source Code

//License from project: Apache License 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;

public class Main{
    public static String readText(String path) throws IOException {

        InputStream resourceAsStream = FileUtil.class
                .getResourceAsStream(path);

        BufferedReader br = new BufferedReader(new InputStreamReader(
                resourceAsStream, Charset.forName("UTF-8")));

        StringBuffer sb = new StringBuffer();

        String line = br.readLine();

        while (line != null) {
            sb.append(line).append("\n");
            line = br.readLine();/* w w  w . j  av  a  2  s. c  om*/
        }

        if (sb.length() > 0) {
            sb.delete(sb.length() - 1, sb.length());
        }

        return sb.toString();
    }
}

Related

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