Paradius
Paradius

Reputation: 8159

Deleting a File using J2ME throws an IOException

I am attempting to delete a file using J2ME's FileConnection.delete() method, but I an IOException is being thrown each time I call the delete() method. I have written a conditional statement to verify the existence of the file, but irregardless of that fact, an IOException is thrown.

According to the FileConnection API, when delete() is called on a FileConnection object, all streams associated with the object are closed, and an IOException is thrown if any subsequent actions on the streams associated with the particular file occur.

The file I am attempting to delete has been recorded within the same program, but after I call the delete() method, I call recordControl.reset(). Would this probably cause the IOException to be thrown?

What could be my problem?

Upvotes: 3

Views: 2265

Answers (3)

Jinesh
Jinesh

Reputation: 841

Check the string including the path that you are passing to Connector.open() ,Verify the file permissions,close all streams opened for that file before deleting.

Upvotes: 1

Markus Lausberg
Markus Lausberg

Reputation: 12257

I believe that someone in your code is connected to the file you want to delete. You should manually close all connections to the existing file and not trust that someone else will do this for you.

Do you have open the file in another application, like notepad?

Upvotes: 4

Bhushan Bhangale
Bhushan Bhangale

Reputation: 10987

IThe exception stack trace will tell you what line of code is throwing IOException and some times you get reason of exception as well, so have a look at the stack trace.

Upvotes: 1

Related Questions