【发布时间】:2019-11-19 14:28:29
【问题描述】:
我已经使用过 java,但发现使用 Kotlin 很困难。
我已经用谷歌搜索过,但它们都不适合我。
/**
* Get the json data from json file.
*
* @param context the context to acces the resources.
* @param fileName the name of the json file
* @return json as string
*/
public static String getJsonFromAsset(Context context, String fileName) {
String json = "";
try {
InputStream stream = context.getAssets().open(fileName);
int size = stream.available();
byte[] buffer = new byte[size];
stream.read(buffer);
stream.close();
json = new String(buffer, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
return json;
}
我想要 Kotlin 中的这段代码。
【问题讨论】: