java - openFileOutput not working -
i'm debugging step step following snippet , doesn't create or read file supposed nor throw excpetion. lives inside main activity of application. wrong lines of code?
public void onclick(view v) { try { fileoutputstream outputstream = openfileoutput("test.txt", context.mode_private); try { outputstream.write("this text".getbytes()); outputstream.close(); fileinputstream inputstream = openfileinput("test.txt"); string string = new string(); inputstream.read(string.getbytes()); toast.maketext(getapplicationcontext(), string, toast.length_long).show(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } catch (filenotfoundexception e1) { // todo auto-generated catch block e1.printstacktrace(); } }
string string = new string(); inputstream.read(string.getbytes()); toast.maketext(getapplicationcontext(), string, toast.length_long).show();
it looks you're trying read data directly string. can't that. strings immutable in java. when call getbytes() on string, not getting internal buffer, getting copy of data.
instead, should reading whole new buffer until the inputstream has not more data, covert string, , display that.
Comments
Post a Comment