Confusion - Which comes first File Mode or File??

Put your problem here if it does not fit any of the other categories.

Confusion - Which comes first File Mode or File??

Postby milkround » Wed Dec 16, 2009 3:28 pm

I have looked at a lot of posts and cannot understand what is required

What I require is to be able to create/read/write/ and DELETE files on the SDCARD from which ever Activity and whichever Thread within my program.

I have been creating files using:-

File newFile = new File ("/sdcard/Milk/wk200949");
if (newFile.createNewFile()){
FileOutputStream fos = new FileOutputStream(newFile);
fos.write(newarray, 0, fsize);

which works fine but the file is created with -rwxrwxrwx permissions so I cannot use the deleteFile(filename) routine to delete it.

If I open the file using

FileOutputStream fos = openFileOutput("/sdcard/Milk/wk200949", MODE_PRIVATE);

then it fails because the file does not exist! NO IT FAILS WITH INVALIDARGUMENT as you can't have paths in the filename

However, Dispite having the file permission -rwxx.... the file can be deleted using:-

new File("SDCARD/.../filename").delete();

Thanks Mark Murphy in a long gone thread.

Which just goes to show "If you ask the wrong question .... You don't necessarily get an answer!!"

Posts: 34
Joined: Sat May 02, 2009 2:29 pm
Location: UK & Malta


Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 18 guests