Android - problem with file-writing
I have some problems when writing an xml file onto my android device (GalaxyTab 10.1V). The code for writing the xml
works fine. I can see the written file at the DDMS
perspective in Eclipse and can save the file to any location on my computer. But when I open the same directory as opened in Eclipse with the windows explorer, it seems that the file does not exist! The file is still visible at the DDMS
perspective, but windows explorer does not want (or can´t?) show me this file. After rebooting the tablet, the file is also shown at the windows explorer.
I have tried several things for solving this problem...
writing a .txt file --> same result
tried
getExternalFilesDir()
(as recommended since API Level 8) andgetExternalStoragePublicDirectory()
instead ofgetExternalStorageDirectory()
--> same resultwriting at USB-Debug mode, writing at "normal" USB mode, writing without USB connection --> same result
of course I have set the permission to read and write on the device at the开发者_开发问答 manifest file
android.permission.WRITE_EXTERNAL_STORAGE android.permission.READ_EXTERNAL_STORAGE
- "show hidden files" is activated at the windows folder options
this is how my code looks like...
public boolean write(Result result) {
Serializer serial = new Persister();
File file = new File(Environment.getExternalStorageDirectory()
+ "/Test/result.xml");
try {
serial.write(result, file);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
I use the SimpleXML library for reading and writing my xml files but as mentioned before, the same problem occurs when writing a normal .txt file
Does anyone have an idea what the reason for this behaviour could be?
精彩评论