android - Using InputStream to read file from internal storage -


i've searched couple days, , find using bufferedreader read file on internal storage. not possible use inputstream read file on internal storage?

private void dailyinput() {         inputstream in;     in = this.getasset().open("file.txt");     scanner input = new scanner(new inputstreamreader(in));     in.close(); } 

i use input.next() search file data need. works fine, save new files internal storage , read them without changing bufferedreader. possible or need bite bullet , change everything? fyi don't need write, read.

to write file.

string filename = "file.txt"; string string = "hello world!";  fileoutputstream fos = openfileoutput(filename, context.mode_private); fos.write(string.getbytes()); fos.close(); 

to read

void openfiledialog(string file) {      //read file in internal storage     fileinputstream fis;     string content = "";     try {         fis = openfileinput(file);         byte[] input = new byte[fis.available()];         while (fis.read(input) != -1) {         }         content += new string(input);     }     catch (filenotfoundexception e) {         e.printstacktrace();     }     catch (ioexception e) {         e.printstacktrace();     } } 

content contain file data.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -