package com.sound.prankparty.Utils;

import com.sound.MainApplication;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class LoadJSON {

    public static String loadJSONFromAsset(String fileName) {
        StringBuilder jsonString = new StringBuilder();
        try {
            //读取filename文件，转换为字符流
            BufferedReader reader = new BufferedReader(new InputStreamReader(MainApplication.getContext().getAssets().open(fileName)));
            String line;
            //逐行读取文件内容，直到文件末尾
            while ((line = reader.readLine()) != null) {
                jsonString.append(line);
            }
            //关闭读取器，释放资源
            reader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        //对象转换为字符串并返回
        return jsonString.toString();
    }

}
