android - Cannot find the file -
i'm experiencing trouble open file. i've used absolute path know file still cant open file (file not found)
public void readfromfile() throws filenotfoundexception { /** read contents of given file. */ string sourceid = new string(); string logicalid = new string(); file filedir = getfilesdir(); string s = new string(); s+=filedir.getabsolutepath()+"/nodes.txt"; scanner scanner = new scanner(new fileinputstream(s)); try { while (scanner.hasnextline()) { sourceid = scanner.nextline(); logicalid = scanner.nextline(); string ss = new string(); ss+=" ----------------> "+sourceid+" "+logicalid+" "; log.v(tag, ss); listanodesstart.add(new nodestostart(sourceid,logicalid)); } }catch(exception ee){//log.v(tag, "could not read file"); error.settext("could not read file nodes.txt"); errorlog.settext("could not read file nodes.txt");} finally{scanner.close(); } } i guess problem device hasn't file, but, how can upload when app starts?
thanks in advance
as mentioned, have no file in device! work static files, insert them in assets folder , then:
assetmanager assetmanager = getassets(); string[] files = null; try { files = assetmanager.list(""); } catch (ioexception e) { log.d("tag", e.getmessage()); } for(string filename : files) { if( filename.equals("nodes.txt") { inputstream in = null; try { // work file in = assetmanager.open(filename); // ... } catch(exception e) { log.e("tag", e.getmessage()); } } }
Comments
Post a Comment