Android Reader Read readFile(String filename)

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

Description

read File

License

Apache License

Declaration

public static String readFile(String filename) 

Method Source Code

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

import java.io.*;

public class Main {
    public static String readFile(String filename) {
        File in = new File(filename);
        try {//from   w  w  w .  ja  v  a  2s  . co m
            Reader fr = new InputStreamReader(new FileInputStream(in),
                    "UTF-8");
            char[] cbuf = new char[(int) in.length()];
            try {
                fr.read(cbuf);
                String ret = String.valueOf(cbuf);
                fr.close();
                return ret;
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. copy(Reader input, OutputStream output)
  2. copy(Reader input, Writer output)
  3. readContents(Reader in)
  4. readFileReader(String filePath)
  5. readTextFile(String fileName)
  6. slurpLines(final Reader reader)
  7. slurpValidLines(final Reader reader)