I won’t say much nonsense, I will just post code to everyone. The specific code is as follows:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Read resource files(Raw)" /> <TextView android: android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> package ; import ; import ; import .; import ; import ; import ; import ; import ; import ; import ; public class MainActivity extends AppCompatActivity { private Button btnRead=null; @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_main); btnRead=(Button)(); //Read resource file(new OnClickListener(){ public void onClick(View v) { //Get resource objectResources res=(); //Read the resource file of the resource through openRawResource(), and the result is returned to InputStreamInputStream input=(); //Read the resource file contentScanner scan=new Scanner(input); StringBuffer info=new StringBuffer(); while(()) (()).append("\n"); (); try { (); } catch (IOException e) { (); } (getApplicationContext(), (),Toast.LENGTH_LONG).show(); } }); } }
We save the file to the res/raw folder.
Note: The raw file does not exist and needs to be created manually.
The above is the relevant knowledge about the access operation of Android resource files introduced to you by the editor. I hope it will help you!