Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * Appcelerator Titanium Mobile
 * Copyright (c) 2011 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import android.util.Log;

public class Main {
    private static final String TAG = "TiAssetHelper";

    public static String readFile(String path) {
        try {
            FileInputStream in = new FileInputStream(path);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            byte buffer[] = new byte[1024];
            int count = 0;

            while ((count = in.read(buffer)) != -1) {
                if (out != null) {
                    out.write(buffer, 0, count);
                }
            }

            return out.toString();

        } catch (FileNotFoundException e) {
            Log.e(TAG, "File not found: " + path, e);

        } catch (IOException e) {
            Log.e(TAG, "Error while reading file: " + path, e);
        }

        return null;
    }
}