java - openFileOutput throws exception -


i writing data xml files in android app. looked how file io , found need use openfileoutput. far can tell there nothing wrong code keeps throwing exception @ line have try-catch wrapped around in following code:

public void writesearchxml(arraylist<string> searches, string file)         throws exception {     // try {     // file newxmlfile = new file(file);     // newxmlfile.createnewfile();     // } catch (exception e) {     // }     try {         // following line throws exception every time         fileoutputstream out = openfileoutput(file,                 context.mode_world_writeable);     } catch (exception e) {         throw new exception("failing on fileoutput stream searches.");     }     fileoutputstream fout = openfileoutput(file,             context.mode_world_readable);     // create xmlserializer in order write xml data     xmlserializer serializer = xml.newserializer();     // set fileoutputstream output serializer, using utf-8     // encoding     serializer.setoutput(fout, "utf-8");     // write <?xml declaration encoding (if encoding not null) ,     // standalone flag (if standalone not null)     serializer.startdocument(null, boolean.valueof(true));     // set indentation option     serializer.setfeature(             "http://xmlpull.org/v1/doc/features.html#indent-output", true);     // start tag called "root"     serializer.starttag(null, "searches");     (string search : searches) {         serializer.starttag(null, "search");         serializer.text(search);         serializer.endtag(null, "search");     }     // // indent code have view similar xml-tree     // serializer.starttag(null, "username");     // serializer.text(username);     // serializer.endtag(null, "username");     // serializer.starttag(null, "password");     // serializer.text(password);     // serializer.endtag(null, "password");     // //serializer.attribute(null, "attribute", "value");     serializer.endtag(null, "searches");     serializer.enddocument();     // write xml data fileoutputstream     serializer.flush();     // close file stream     fout.close(); } 

the problem in code 1 line. i've searched on internet , haven't been able fine solution. can fix this?

update: exception being thrown filenotfound exception. leads me believe openfileoutput function doesn't create file says in description. can in android create file without using openfileoutput?

i found answer here: android wrong openfileoutput?

openfileoutput has called using activity's context.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -