Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class Main {
    public static JSONObject readJSONFile(String path) {
        String file = new String(), tmp;
        try {
            // Read the file
            BufferedReader bf = new BufferedReader(new FileReader(new File(path)));
            while ((tmp = bf.readLine()) != null) {
                file += tmp;
            }
            bf.close();

            // Parse the JSON
            JSONObject jso = new JSONObject(file);
            return jso;
        } catch (JSONException e) {
            Log.e("JSO reading", "Error parsing the JSO file " + path + "\n" + e.getMessage());
        } catch (IOException e) {
            Log.e("JSO reading", "Error reading the file " + path + "\n" + e.getMessage());
        }

        return null;
    }
}