In depth analysis of the difference between asset folder and raw folder in Android

*The similarities between RES / raw and assets: 1. The files in the two directories will be saved intact in the APK package after packaging, and will not be compiled into binary. 2* Differences between RES / raw and assets: 1. The files in RES / raw will be mapped to the r.java file, and the resource ID, i.e. r.id.filename, will be used directly when accessing; The files in the assets folder will not be mapped to r.java. Assetmanager class is required when accessing. 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 obtain the input stream to write ・ InputStream is = getresources(). Openrawresource (r.id.filename); 2. Read the file resources under assets and obtain the input stream to write in the following ways ・ assetmanager am = null; ・ am = getAssets(); ・ InputStream is = am.open("filename");

Note 1: there is a bug in the processing of assert in Google's Android system. You can't process a single file exceeding 1MB in the assetmanager, otherwise an exception will be reported. Raw doesn't have this limit. It's OK to put 4MB MP3 files.

Note 2: the assets folder stores native files that are not compiled, that is, the files in this folder will not be precompiled like XML and java files, but can store some pictures, HTML, JS, CSS and other files.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>