Convert assets file to byte[]

Note: After the assets file is installed on the phone, there is no absolute path in the phone, only relative path!!!

Code:

animRes.m_AnimSklFile = readFileFromAssets(this.getActivity(),null,"animation.skl");
animRes.m_AnimFiles[0] = readFileFromAssets(this.getActivity(),null,"animation.anim");
......
public static byte[] readFileFromAssets(Context context, String groupPath, String filename){
    byte[] buffer = null;
    AssetManager am = context.getAssets();
    try {
        InputStream inputStream = null;
        if (groupPath != null) {
            inputStream = am.open(groupPath + "/" + filename);
        } else {
            inputStream = am.open(filename);
        }

        int length = inputStream.available();
        ArcLog.d(TAG, "readFileFromAssets length:" + length);
        buffer = new byte[length];
        inputStream.read(buffer);
    }catch (Exception exception){
        exception.printStackTrace();
    }
    return buffer;
}

 

Guess you like

Origin blog.csdn.net/u012906122/article/details/103653611