Two ways to embed resource files in an Android project


Method 1

res/raw directory, such as cwj.dat1 binary file, we can read it directly


InputStream is=context.getResources().openRawResource(R.raw.cwj);

Method 2

In the assets folder in the project root, for example, assets/ cwj.dat, we use the following code


AssetManager am = context.getAssets();
InputStream is = am.open(cwj.dat);

Here, Android123 indicates that Google’s Android system has an bug for Assert. In AssertManager, you can’t handle a single file larger than 1MB, otherwise it will report an abnormal value. You can test and upload a larger file, as we mentioned in the paper two years ago.