Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStreamReader;
import android.content.Context;

public class Main {
    public static String readFile(Context ctx, String filename) {
        FileInputStream fis = null;
        String line = null;
        StringBuilder sb = new StringBuilder();
        try {
            fis = new FileInputStream(ctx.getFilesDir() + File.separator + filename);
            InputStreamReader inputStreamReader = new InputStreamReader(fis);
            @SuppressWarnings("resource")
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            while ((line = bufferedReader.readLine()) != null) {
                sb.append(line);
            }
        } catch (Exception e) {
            //e.printStackTrace();
            return null;
        } finally {
            try {
                if (fis != null)
                    fis.close();
            } catch (IOException e) {
                return null;
            }
        }

        return sb.toString();
    }
}