java - Have a greater number than 256 android file output stream -
i using fos.write(some_number)
when trying display number won't greater 255.
this second activity's code:
fileoutputstream fos; try { fos = openfileoutput("income", context.mode_private); //"income" number written on textfield fos.write(income); fos.close(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); }
first activity's code:
try { fileinputstream fis; fis = openfileinput("income"); total_income = fis.read(); fis.close(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } //... //.... textview textview = (textview) findviewbyid(r.id.incomevalue); textview.settext(""+ total_income);
the write() method writes byte has range 0-255, won't more that.
better use dataoutputstream , datainputstream like:
fileoutputstream fos; try { fos = openfileoutput("income", context.mode_private); dataoutputstream dos = new dataoutputstream(fos); dos.writeint(income); dos.close(); fos.close(); } catch (ioexception e) { e.printstacktrace(); }
and 1st activity:
try { fileinputstream fis; fis = openfileinput("income"); datainputstream dis = new datainputstream(fis); total_income = dis.readint(); dis.close(); fis.close(); } catch (ioexception e) { e.printstacktrace(); } textview textview = (textview) findviewbyid(r.id.incomevalue); textview.settext(""+ total_income);
Comments
Post a Comment