The difference between asset and Raw in Android

Source: Internet
Author: User

*res/raw and the Assets the same point:

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


different points of *res/raw and assets :
1.res/rawwill be mapped to the file in theR.javafiles, use resources directly when accessingIDthatR.id.filename;Assetsfiles under the folder are not mapped toR.javaduring the visit, you need toAssetmanagerclass.
2.Res/rawthere can be no directory structure, andAssetsYou can have a directory structure, which isAssetsfolder can be created under directory

* To read a file resource:

1. read The file resource under the Res/raw, and get the input stream for write operation in the following way

· InputStream is =getresources (). Openrawresource (R.id.filename);

2. read The file resource under the assets, and get the input stream for write operation in the following way

· Assetmanager am = null;

· am = getassets ();

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

Note 1 : Google's Android system processing assert has a bug, in the Assertmanager can not process a single more than 1MB files, or will be reported abnormal, raw without this limit can put a 4MB Mp3 file no problem.

Note 2 :Assets folder is a native file that is not compiled and processed, that is, the files inside the folder will not be like XML, Java files are precompiled, can be stored in some pictures, Html,js, CSS and other files.

The difference between asset and Raw in Android

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.