Android: How to write to a certain line, Java -
hello guys , thanks,
i wondering how write line in java android. here write method:
public void savelesson(int lessons2, int problem2, int mlessons2, int mproblem2, string checkaccuracy) { string newline = system.getproperty("line.separator"); final string saved = new string(lessons2 + newline + problem2 + newline + mlessons2 + newline + mproblem2 + newline + checkaccuracy); fileoutputstream fout = null; try { // catches ioexception below fout = openfileoutput("lessonstore.properties", context.mode_private); } catch (filenotfoundexception e) { // todo auto-generated catch block e.printstacktrace(); } outputstreamwriter osw = new outputstreamwriter(fout); // write string file try { osw.write(saved); /* ensure * written out , close */ osw.flush(); osw.close(); } catch (ioexception e) { toast andeggs = toast.maketext(lessons.this, "error while writing...", toast.length_short); andeggs.show(); // todo auto-generated catch block e.printstacktrace(); } }
how make overwrite line 3, instead of whole thing because save variables , nice have save 1 instead of them all.
how make overwrite line 3
you don't!
never modify file in line; if line shorter original? if it's longer? os won't automagically expand/shrink file you!
write contents another file, replace original.
Comments
Post a Comment