在raw文件中读取json文件转换为InputStream.
getResources().openRawResource(R.raw.song_sheet_data)
在根据InputStream流转换为字符串的工具类
public static String inputStreamToString(InputStream inputStream) {
try {
byte[] bytes = new byte[inputStream.available()];
inputStream.read(bytes, 0, bytes.length);
String json = new String(bytes);
return json;
} catch (IOException e) {
return null;
}
}
转换简单直接
本文介绍了一种从Android项目的raw资源文件夹中读取JSON文件的方法,并将其转换为InputStream,进而通过工具类将InputStream转换成字符串的过程。
986

被折叠的 条评论
为什么被折叠?



