get File Content as String by file name - Android File Input Output

Android examples for File Input Output:Text File

Description

get File Content as String by file name

Demo Code


//package com.java2s;
import android.content.Context;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static String getContent(Context context, String fileName) {
        try {/*from www  .j  a v  a 2 s . c  o  m*/
            InputStreamReader inputReader = new InputStreamReader(context
                    .getResources().getAssets().open(fileName));
            BufferedReader bufReader = new BufferedReader(inputReader);
            String line = "";
            String Result = "";
            while ((line = bufReader.readLine()) != null)
                Result += line;

            System.out.print(Result);
            return Result;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related Tutorials