package com.xyxsbj.mylibrary.tool;


import android.content.Context;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * 创建人 mQ
 * 创建时间 2019/5/20 0020 10:35
 * 文件名称 AssetsTool
 * 说明:
 **/
public class AssetsTool {

    public static String getFromAssets(Context context, String fileName) {
        try {
            InputStreamReader ir = new InputStreamReader(context.getAssets().open(fileName));
            BufferedReader br = new BufferedReader(ir);
            String line = "";
            StringBuilder result = new StringBuilder();
            while ((line = br.readLine()) != null) {
                result.append(line);
            }
            LogTool.i("getFromAssets: 读取assets: " + result.toString());
            return result.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static byte[] getFromAssetsToByte(Context context, String fileName) {
        try {
            InputStream is = context.getAssets().open(fileName);
            int lenght = is.available();
            byte[] result = new byte[lenght];
            is.read(result);
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

}
