I am trying to clear all the files in a folder using j2me. How do I do that?
Clear folder - delete files in folder - J2ME
2.6k views Asked by JohnDoe4136 At
2
There are 2 answers
2
On
Use File.list() or File.listFiles() to get a list of the files. Then iterate the list and use File.delete() to delete them. The use File.delete() to delete the directory.
If you want to include subdirectories, do the previous code recursively, recursing as you hit each subdirectory, before you delete the directory.
Since you are using J2ME, the
java.io.File
class is not available to you.So I am assuming that you are using the FileConnector Optional Package (FCOP).
Take a look at the javadocs for javax.microedition.io.file.FileConnection, and you should be able to figure out the details.
I'm not a J2ME expert, but I think that the code would look something like this:
Exception handling, proper resource handling (using
finally
) is left as an exercise for the reader :-)