views:

1501

answers:

1

I found out that you can use something like this to create a file:

FileOutputStream  fs = openFileOutput("/test.in", MODE_WORLD_WRITEABLE);
String s = "[Head]\r\n";
s += "Type=2";
byte[] buffer = s.getBytes();
fs.write(buffer);
fs.close();

When running the above code I get an IllegalArgumentException stating:

java.lang.IllegalArgumentException: File /test.in contains a path separator

and Im guessing the "/" is not appreciated. I wanted the "/" since I need to write the file to the root directory of the device, as stated in the API in trying to follow:

A request is a textfile (UNICODE) with the file extension ".in". The application reads and parses the .in file when it's placed in root directory on the mobile device.

Question is: how do I place a file in the root-directory? I have been looking around for an answer, but havent found one yet.

regards

+4  A: 

Context.openFileOutput is meant to be used for creating files private to your application. they go in your app's private data directory. you supply a name, not a path: "name The name of the file to open; can not contain path separators".

http://developer.android.com/reference/android/content/Context.html#openFileOutput(java.lang.String, int)

as for your question, you can't write to / unless you're root:

my-linux-box$ adb shell ls -l -d / drwxr-xr-x root root 2010-01-16 07:42 $

i don't know what your API is that expects you to write to the root directory, but i'm guessing it's not an Android API and you're reading the wrong documentation ;-)

Elliott Hughes
Thanks for the answer. Its the only API available to "communicate" with this Application. You communicate by creating text-files in the root directory as quoted above. So its not the wrong documentation - its the only one that exists. I will contact them and ask how they expect that to work on Android =)
Ted
Are you sure it doesn't need you to write to the root directory of the SD card?
mbaird