The Main.xml code is as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" fill_parent " android:layout_height=" fill_parent " android:o rientation= "vertical" > <textview android:id= "@+id/mytext" android:layout_width= "Wrap_content " android:layout_height=" Wrap_content "/></linearlayout>
. Java code is as follows:
Package Org.lxh.demo;import Java.io.ioexception;import Java.io.inputstream;import java.util.scanner;import Android.app.activity;import Android.app.alertdialog;import Android.app.dialog;import Android.content.dialoginterface;import Android.content.res.resources;import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.view.onfocuschangelistener;import Android.widget.button;import Android.widget.edittext;import Android.widget.textview;public class Hello extends Activity {private TextView mytext = Null;public void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Life cycle Method Super.setcontentview (R.layout.main); Set the layout manager to use This.mytext = (TextView) Super.findviewbyid (R.id.mytext); Resources res = super.getresources ();//resource operation class InputStream input = Res.openrawresource (R.raw.mybook);//Read Resource Idscanner Scan = new Scanner (input),//stringbuffer buf = new StringBuffer ();//for receiving data while (Scan.hasnext ()) {Buf.append (Scan.next ( ). AppEnd ("\ n");} Scan.close (); try {input.close ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();} This.mytext.setText (Buf.tostring ());}}
Run as follows:
Android--Operating resource files