What is the difference between asset and raw in Android? androidassetraw

Source: Internet
Author: User

What is the difference between asset and raw in Android? androidassetraw

* Similarities between res/raw and assets:

1. Files in the two directories will be stored in the apk package intact after packaging, and will not be compiled into binary.


* Differences between res/raw and assets:
1. files in res/raw will be mapped to R. in the java file, the resource ID is R. id. filename; files in the assets folder will not be mapped to R. in java, the AssetManager class is required for access.
2. res/raw cannot have a directory structure, while assets can have a directory structure, that is, folders can be created under the assets Directory.

* Read File resources:

1. Read the file resources under res/raw and get the input stream for write operations in the following ways

· InputStream is = getResources (). openRawResource (R. id. filename );

2. Read the file resources under assets and get the input stream for write operations in the following ways

· AssetManager am =Null;

· Am = getAssets ();

· InputStream is = am. open ("filename ");

 

 

Note 1: Google's Android system has a bug in processing Assert. In AssertManager, a single file exceeding 1 MB cannot be processed. Otherwise, an exception is reported, there is no such limit for raw to store a 4 MB Mp3 file.

 

Note 2: The assets folder stores native files that are not compiled and processed, that is, the files in this folder are not like xml, java files are pre-compiled, and some images, html, js, and, css files.

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.