android - Reading text file keeping previous format -


im making simple network app , want load chat log on start up, works fine formats text 1 line

writing file

charsequence cs = tv.gettext (); final string str = cs + "\r\n" + s; //write text file try { fileoutputstream fos = openfileoutput("chat log", context.mode_append); fos.write(s.getbytes()); fos.close(); } catch (exception e) { e.printstacktrace(); }    } catch (ioexception e1) {  e1.printstacktrace(); } //close socket socket.close();  

reading text

final textview tv = (textview)findviewbyid(r.id.textview1); try { bufferedreader inputreader = new bufferedreader(new inputstreamreader( openfileinput("chat log"))); string inputstring; stringbuffer stringbuffer = new stringbuffer(); while ((inputstring = inputreader.readline()) != null) { stringbuffer.append(inputstring + "\r\n"); tv.append(inputstring); }  } catch (ioexception e) { e.printstacktrace(); } 

current result screenshot

you should able save formatting using html.tohtml , html.fromhtml.

something along lines of:

string htmlformatted = html.tohtml(tv.gettext()); // .. save file .. 

then:

spanned htmlformatted = html.fromhtml(chatlog); tv.settext(htmlformatted); 

see these similar questions:


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -