Saving file on SD card
<p>I've got problem with writing files on the SD card in the emulator. Here is my code:</p>

<pre><code>File directory;
directory = new File("/sdcard/b/b");
directory.mkdirs();
...
XmlSerializer serializer = Xml.newSerializer();
StringWriter writer = new StringWriter();
serializer.setOutput(writer);
...
String fileName = new Date().toString();

FileOutputStream fOut = healthCareApplication.openFileOutput("/sdcard/b/b"+fileName+".xml",Context.MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut); 
osw.write(writer.toString());
osw.flush();
osw.close();
</code></pre>

<p>Firstly I create directory on the SD card, next I build some XML file. Then I try to create a file and try to save this XML File to this directory, but I get IllegalArgumentException and application crashes. "healthCareApplication" is class which extends the application class. What is wrong with this code?</p>

<p><strong>EDIT</strong></p>

<p>Ok, I add "Environment.getExternalStorageDirectory().getAbsolutePath();" and here is what I get in Logcat:</p>

<pre><code>08-13 16:29:34.168: ERROR/AndroidRuntime(419): FATAL EXCEPTION: pool-1-thread-5
08-13 16:29:34.168: ERROR/AndroidRuntime(419): java.lang.IllegalArgumentException:    File /mnt/sdcard/c/c/Sat Aug 13 16:29:34 GMT+00:00 2011.xml contains a path separator
08-13 16:29:34.168: ERROR/AndroidRuntime(419):     at android.app.ContextImpl.makeFilename(ContextImpl.java:1648)
08-13 16:29:34.168: ERROR/AndroidRuntime(419):     at android.app.ContextImpl.openFileOutput(ContextImpl.java:414)
08-13 16:29:34.168: ERROR/AndroidRuntime(419):     at android.content.ContextWrapper.openFileOutput(ContextWrapper.java:158)
08-13 16:29:34.168: ERROR/AndroidRuntime(419):     at com.myapp.runnable.ServerWorker.packageToXML(ServerWorker.java:197)
08-13 16:29:34.168: ERROR/AndroidRuntime(419):     at com.myapp.runnable.ServerWorker.run(ServerWorker.java:85)
08-13 16:29:34.168: ERROR/AndroidRuntime(419):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
08-13 16:29:34.168: ERROR/AndroidRuntime(419):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
08-13 16:29:34.168: ERROR/AndroidRuntime(419):     at java.lang.Thread.run(Thread.java:1019)
</code></pre>

<p>When I checking DDMS I see that the folder is created in sdcard but in that directory in is nothing so probably problem is occurred when application trying to write file to sdcard.</p>

<p>I also replace </p>

<pre><code>"FileOutputStream fOut = healthCareApplication.openFileOutput("/sdcard/b/b"+fileName+".xml",Context.MODE_WORLD_READABLE);" 
</code></pre>

<p>for </p>

<pre><code>File outputFile = new File(wallpaperDirectory, fileName);
FileOutputStream fos = new FileOutputStream(outputFile);
</code></pre>

<p>and get another exception: </p>

<pre><code>08-13 16:46:56.108: INFO/IOException(3110): /Sat Aug 13 16:46:56 GMT+00:00 2011 (Read-only file system)
</code></pre>
