讀取assets的json工具類
阿新 • • 發佈:2018-12-20
public class JsonFileReader { public static String getJson(Context context, String fileName) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { AssetManager assetManager = context.getAssets(); InputStream inputStream = assetManager.open(fileName); BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); byte[] buffer = new byte[1024]; int len; while ((len = bufferedInputStream.read(buffer)) != -1) { baos.write(buffer, 0, len); } } catch (IOException e) { e.printStackTrace(); }finally { try { baos.close(); } catch (IOException e) { e.printStackTrace(); } } return baos.toString(); } }
上方讀出來是一個字串至於解析就要大家自己寫了