About the usage of raw in Android and the differences and similarities with assets

Source: Internet
Author: User

I. Differences and similarities between raw and assets

(1) Similarities of Res/raw and assets

The files in the two directory will be stored in the APK package intact after packaging and will not be compiled into binary.


(2) different points of Res/raw and assets:

The files in the 1.res/raw are mapped to the R.java file and are accessed directly using the resource ID, which is r.raw.filename;

The files under the Assets folder are not mapped to R.java, and the Assetmanager class is required for access.


2.res/raw can not have a directory structure, and assets can have a directory structure, that is, assets directory can be re-established folder


Two. Read the file resources:


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

Resources resource=getresources ();

InputStream is =resource.openrawresource (r.raw.filename);


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


Assetmanager am = getassets ();
InputStream is = am.open ("filename");


Note 1:google's Android system handles assert when there is a bug, in Assertmanager can not process a single more than 1MB of files, or will be reported abnormal, raw no this limit can put a 4MB Mp3 file no problem.


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

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.