i want read json file have large amount of data
my code
public string loadjsonfromasset() { f = new file(environment.getexternalstoragedirectory().getpath() + "/contact backup/name.json"); string json = null; try { inputstream is; = new bufferedinputstream(new fileinputstream(f)); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); json = new string(buffer, "utf-8"); } catch (ioexception ex) { ex.printstacktrace(); return null; } return json; }
in logcat, shows half json file readed.
any help?
do not read byte byte , read lind line using scanner class.
example
public string loadjsonfromasset() { file = new file(environment.getexternalstoragedirectory().getpath() + "/contact backup/name.json"); final stringbuilder text = new stringbuilder(); try { scanner sc = new scanner(file); while (sc.hasnextline()) { text.append(sc.nextline()); } sc.close(); } catch (exception ex) { ex.printstacktrace(); } return text.tostring(); }
Comments
Post a Comment