Back to project page fileEx.
The source code is released under:
Apache License
If you think the Android project fileEx listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package android.howard.exp.utils; //from w w w . j a v a2 s . c o m import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import android.content.Context; public class TextFileReader { private Context mContext; /** * @param mContext */ public TextFileReader(Context mContext) { super(); this.mContext = mContext; } public String read(String filename) { try { FileInputStream fis = null; InputStreamReader reader = null; BufferedReader br = null; try { fis = new FileInputStream(filename); reader = new InputStreamReader(fis, "utf-8"); br = new BufferedReader(reader); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } StringBuffer sb = new StringBuffer(""); String lineString; try { while ((lineString = br.readLine()) != null) { sb.append(lineString); sb.append("\n"); } fis.close(); br.close(); return sb.toString(); } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } return null; } }