from Raw Resource File : Resources « Core Class « Android

Home
Android
1.2D Graphics
2.Animation
3.Core Class
4.Database
5.Date Type
6.Development
7.File
8.Game
9.Hardware
10.Media
11.Network
12.Security
13.UI
14.User Event
Android » Core Class » Resources 
from Raw Resource File
    
//package com.retain;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.Date;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;

/**
 @author Nazmul Idris
 @version 1.0
 @since Jul 8, 2008, 2:35:39 PM
 */
class AppUtils {

  /**
   * 127.0.0.1 in the emulator points back to itself. Use this if you want to
   * access your host OS
   */
  public static String EmulatorLocalhost = "10.0.2.2";

  public static String fromRawResourceFile(int id, Context ctx) {
    String data = "";
    try {
      InputStream is = ctx.getResources().openRawResource(id);
      InputStreamReader isr = new InputStreamReader(is);

      BufferedReader br = new BufferedReader(isr);
      String thisLine;
      while ((thisLine = br.readLine()) != null) {
        data += thisLine;
      }
      is.close();

    catch (Exception e) {
      Log.e("fromRawResourceFile",
          "Error: " + e.getMessage() "," + e.toString());
    }

    return data;
  }


}// end class AppUtils

   
    
    
    
  
Related examples in the same category
1.Resources Management
2.Load resource from raw folder
3.Multiple Resource
4.Demonstration of loading resources.
5.Need the following import to get access to the app resources, since this class is in a sub-package.
6.Demonstration of styled text resources.
7.Demonstrates using -wNNNdp and -hNNNdp resource configs.
8.Resources width and height
9.Load resource
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.