Android reads the contents of the Assets folder

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.