* 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" );
files in the assets folder are in the original file format and must be read in byte streams using assetmanager.
1. Call getassets () In the activity to obtain the assetmanager reference.
2. Use the open (string filename, int accessmode) method of assetmanager to specify the file to be read and the access mode to obtain the input stream inputstream.
3. Use inputstream of the open file to read the file. After reading the file, remember inputstream. close () .
4. Call assetmanager. close () close assetmanager