Usage of resource folders Res/raw and assets in Android

Source: Internet
Author: User

* 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; <br/> AM = getassets (); <br/> inputstream is = aM. Open ("FILENAME ");

 

Add: What files are in the unknown directory? Should I get the names of these files and copy them to the target directory? (Used for built-in files but do not know the file name. You need to filter out the desired files and copy them to the target directory. We recommend that you build them in the assets folder)
1. Res/raw directory:
Obtain the names of all resource IDs in the raw internal class in R. Java through reflection, and then obtain the value of the resource ID through the name to read the desired file. (I have never tried this method. If you have used this method, please send a piece of code ).
2. Assets Directory:
Getassets (). List (""); to get the names of all folders and files under the assets directory, and then read the desired files through these names.

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.