Monday, 15 June 2015

java - Reading a textfile using InputStream -



java - Reading a textfile using InputStream -

how can read text file in android app:

"1.something written 2.in file 3.is read 4.the inputstream ..."

so can returned string like:

"something written/nin file/nis read by/n/nthe inputstream"

what thought of is(pseudocode):

make inputstream = getassest().open("textfile.txt"); //in seek , grab loop{ string = is.read() , if equals "." (i.e. 1., 2., 3. etc) add together "/n" ... }

try

import android.app.activity; import android.os.bundle; import android.widget.toast; import java.io.*; public class filedemo1 extends activity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); seek { playwithrawfiles(); } grab (ioexception e) { toast.maketext(getapplicationcontext(), "problems: " + e.getmessage(), 1).show(); } } public void playwithrawfiles() throws ioexception { string str = ""; stringbuffer buf = new stringbuffer(); inputstream = this.getresources().openrawresource(r.drawable.my_base_data); seek { bufferedreader reader = new bufferedreader(new inputstreamreader(is)); if (is != null) { while ((str = reader.readline()) != null) { buf.append(str + "\n" ); } } } { seek { is.close(); } grab (throwable ignore) {} } toast.maketext(getbasecontext(), buf.tostring(), toast.length_long).show(); } }

java android inputstream

No comments:

Post a Comment