Custom Folder in Android Project -
i need put folder in android project can access using file mydir = new file(path-to-dir);
can't seem find way this. have tried putting in assets
folder need access folder itself, can perform operations on once have in file
object. appreciated.
step 1 : create folder ins assets folder , place files there..
step 2 : assuming have folder named myfolder in assets folder, try code
readfromfile("/myfolder/myfile.txt", mcontext);
and function
public string readfromfile(string filename, context context) { stringbuilder returnstring = new stringbuilder(); inputstream fin = null; inputstreamreader isr = null; bufferedreader input = null; try { fin = context.getresources().getassets() .open(filename, context.mode_world_readable); isr = new inputstreamreader(fin); input = new bufferedreader(isr); string line = ""; while ((line = input.readline()) != null) { returnstring.append(line); } } catch (exception e) { e.getmessage(); } { try { if (isr != null) isr.close(); if (fin != null) fin.close(); if (input != null) input.close(); } catch (exception e2) { e2.getmessage(); } } return returnstring.tostring(); }
credits so question
Comments
Post a Comment