package com.mogo.utils; import android.content.Context; import android.text.TextUtils; import android.util.Log; import java.io.BufferedInputStream; import java.io.InputStream; /** * @author congtaowang * @since 2019-12-12 *

* 读取asset文件 */ public class AssetsUtils { private static final String TAG = "amap.AssetsUtils"; public static byte[] read( Context context, String fileName ) { if ( context == null || TextUtils.isEmpty( fileName ) ) { return null; } byte[] buffer = null; try { InputStream is = context.getAssets().open( fileName ); BufferedInputStream bis = new BufferedInputStream( is ); buffer = new byte[is.available()]; bis.read( buffer ); bis.close(); is.close(); Log.d( TAG, "read assets success: " + fileName + " size=" + buffer.length ); } catch ( Exception e ) { e.printStackTrace(); } return buffer; } }