Hi, Use File.separator instead of /.
This might be obvious but make sure SD card is not mounted on PC when running your code & debugging. Yes Context Provider is 'best' particularly for sharing with other apps, but involves a lot more work. Also I would not bother to check if file exits & create it I would just write to it regardless unless you don't want to overwrite it. Regards On Sep 26, 10:35 pm, ksmobilejava <[email protected]> wrote: > To create new xml file on SD card I am using following code > String strFileName = Environment.getExternalStorageDirectory()+"/" + > "temp.xml"; > try{ > > if(!lXmlfile.exists()) > { > > lXmlfile.createNewFile(); > } > > }catch(IOException e){ > > > Log.e("IOException", e.toString()); > > return null; > } > Above code giving me IO exception Permission denied. Although I have > added permission in AndroidManifest.xml > like: > <uses-permission > android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> > > still , can not create file. where am I going wrong? how can I test > this on emulator (create file on which path?) .Pls help its urgent. > One more question: Is user defined content provider is the best way to > complete this requirement(saving and retrieving form data that also > contains image). Pls share. > Regards > > On Sep 26, 7:41 am, gjs <[email protected]> wrote: > > > > > > > > > Hi, > > > Seehttp://developer.android.com/reference/android/content/Context.html#g...() > > > andhttp://developer.android.com/guide/topics/data/data-storage.html > > > Regards > > > On Sep 23, 7:28 pm, ksmobilejava <[email protected]> wrote: > > > > Hello , > > > developing application withformhaving multiple fields, at the end > > > user need to submit the information. > > > On this event, all thedataneed to be stored inXMLfile. > > > thusXMLwrite is required. plus when user asks for particular id then > > > thedatafilled by that id is also to be displayed thusXMLread is > > > required.(search operation) > > > Following is the code I tried for generating samplexml. > > > /////////////////////////////////////////////////////////////////////////// > > > ////////////////// > > > FileOutputStream fileos = null; > > > try{ > > > > > > fileos=openFileOutput("newxml.xml",Context.MODE_PRIVATE); > > > Log.v("info","fileoutput open"); > > > // fileos = new > > > FileOutputStream(newxmlfile); > > > }catch(FileNotFoundException e){ > > > Log.e("FileNotFoundException", > > > "can't create > > > FileOutputStream"); > > > } > > > // create a XmlSerializer in order to > > > writexmldata > > > XmlSerializer serializer > > > =Xml.newSerializer(); > > > try { > > > //we set the FileOutputStream as > > > output for the > > > serializer, using UTF-8 encoding > > > > > > serializer.setOutput(fileos, "UTF-8"); > > > //Write <?xmldeclaration > > > with encoding (if encoding not null) > > > and 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 a tag called > > > "root" > > > serializer.startTag(null, > > > "root"); > > > //i indent code just to > > > have a view similar toxml-tree > > > > > > serializer.startTag(null, "child1"); > > > > > > serializer.endTag(null, "child1"); > > > > > > > serializer.startTag(null, "child2"); > > > //set an > > > attribute called "attribute" with a "value" for > > > <child2> > > > > > > serializer.attribute(null, "attribute", "value"); > > > > > > serializer.endTag(null, "child2"); > > > > > > > serializer.startTag(null, "child3"); > > > //write some text > > > inside <child3> > > > > > > serializer.text("some text inside child3"); > > > > > > serializer.endTag(null, "child3"); > > > > serializer.endTag(null, > > > "root"); > > > serializer.endDocument(); > > > //writexmldataintothe > > > FileOutputStream > > > serializer.flush(); > > > //finally we close the > > > file stream > > > fileos.close(); > > > > //TextView tv = > > > (TextView)this.findViewById(R.id.result); > > > //tv.setText("file has > > > been created on SD card"); > > > Log.v("info","file has > > > been created on SD card"); > > > return true; > > > } catch (Exception e) { > > > Log.e("Exception","error > > > occurred while creatingxmlfile"); > > > return false; > > > } > > > /////////////////////////////////////////////////////////////////////////// > > > /////////////////////////// > > > executed this with actual device but, no newxmlfile is created. > > > where tostorethis programatically createdxmlfile? > > > On emulator if I want to test this application, where thexmlfile > > > will get stored? > > > Pls guide me whats going wrong? > > > Thanks. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

