In addition to being able to create and use files at run time, you can also place files in the package at design time so that they can be used at runtime. For example, you want to pack some help files into a program that you can show them when they need it. In this case, you should put the file under the Res/raw folder.
To use this file in code, you need to invoke the Getresources () method of the activity and return a resources object. Then, use its Openrawresource () method to open the files in the Res/raw folder:
/** called when the "activity is" is a
. * *
@Override public
void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (r.layout.main);
TextBox = (edittext) Findviewbyid (R.ID.TXTTEXT1);
InputStream is = This.getresources (). Openrawresource (r.raw.textfile);
BufferedReader br = new BufferedReader (new InputStreamReader (IS));
String str = null;
try {
while (str = Br.readline ())!= null) {
toast.maketext (Getbasecontext (),
str, toast.length_short) . Show ();
Is.close ();
Br.close ();
} catch (IOException e) {
e.printstacktrace ();
}
}
Note that the ID of the textfile.txt is R.raw.textfile