Android reads the contents of the Assets folder
Assets folder is a directory in the Android program to store relevant external files, Android has provided the appropriate way to access the contents of the folder, so we do not need to carry out the relevant path judgment and other code operations, Directly call the relevant method to open the file and get a byte input stream (InputStream), and then read the byte by the corresponding character encoding into the character input stream (InputStreamReader) And then read the text through Bufferreader to the character input stream and buffer the characters to provide efficient reading of the characters, arrays, and segments, and finally we can read the contents of the file row by line.
Mainactivity.java
Public class mainactivity extends Activity {@Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main);Try{InputStream InputStream = getresources (). Getassets (). Open ("Info.txt"); InputStreamReader InputStreamReader =NewInputStreamReader (InputStream,"UTF-8"); BufferedReader BufferedReader =NewBufferedReader (InputStreamReader); String info =""; while(info = bufferedreader.readline ())! =NULL) {LOG.I ("FFF", info); Toast.maketext (mainactivity. This, info, +). Show (); } }Catch(IOException e) {E.printstacktrace (); } }}
Android reads the contents of the Assets folder