欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

assets文件转为byte[]

程序员文章站 2022-07-14 21:54:54
...

assets文件在apk安装到手机后,在手机里没有绝对路径,只有相对路径!!!

assets文件转为byte[]

代码:

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;
}

 

相关标签: Android应用开发