Why need such type of resources,we can get data from /assets,/res folders and now I am going to show /res/raw folder.
It is simple,raw resources are not compiled by the platform,they available as raw files and these files can refer to any type of files. When you need to include raw files in your application you can do so using /res/raw resources location. When you will place files here,they will be available as raw resources. Getting raw resources is similar to getting files,you need InputStream,and you use Context. Context you will use for getting Resources and after that you can get your raw file. It is simple:
InputStream inputStream = getResources().openRawResource(R.raw.rawresource);
I am going to show example how you can access and read files from /res/raw folder,file for my example which is located under raw folder is simple text file.
Okay. Let’s look to the example:
import java.io.IOException;import java.io.InputStream;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.EditText;public class Main extends Activity{private static String LOG_APP_TAG = "tag";private EditText editField; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); editField = (EditText) findViewById(R.id.textId); findViewById(R.id.btn).setOnClickListener(new View.OnClickListener(){@Overridepublic void onClick(View v){InputStream inputStream = null;try{inputStream = getResources().openRawResource(R.raw.hello_world);byte[] reader = new byte[inputStream.available()];while (inputStream.read(reader) != -1){}editField.setText(new String(reader));editField.setSelection(editField.getText().length())} catch(IOException e){Log.e(LOG_APP_TAG,e.getMessage())} finally{if (inputStream != null){try{inputStream.close()} catch (IOException e){Log.e(LOG_APP_TAG,e.getMessage())}}}}}); }}As you can see after receiving InputStream object I can do what I want. Here I read this file’s data and set this data to EditText component.
Note: don’t forget that raw files can be not only text files they can be in any formats.
Was it useful for you? Leave a comment.
No related posts.

Can I open them for Writing?
Hi.
You can’t. You can use these files only for reading.
Can I look for values from a database created in either excel or access?
Sure. You can.
I used external lib for excel data –POI-HSSF and POI-XSSF and for access data –Jackcess
I will create posts for these problems.
I’am using Escipse Java IDE ,with Android 2.0 installed but cannot find /res/raw folder,only /res/ drawable and res/layout folders.
Can I put raw resources like audio files in Assests folder instead
Hi Anthony. You need create folder raw manually in res directory,it is normal practice. By default res folder contains only drawable(hdpi,ldpi,mdpi),values,layout.
Sure you can put audio,video,etc to assets folder. Pay attention the difference between res and assets is that Android doesn’t generate IDs for assets content.