Clear folder - delete files in a folder - J2ME

I am trying to clear all files in a folder using j2me. How to do it?

+3
source share
2 answers

Since you are using J2ME, the class is java.io.Filenot available to you.

Therefore, I assume that you are using the optional FileConnector package (FCOP).

Take a look at javadocs at javax.microedition.io.file.FileConnection and you should be able to figure out the details.

I am not a J2ME expert, but I think the code will look something like this:

FileConnection fconn = (FileConnection) Connector.open("file:///SomeDirectory");
Enumeration en = fconn.list();
while (en.hasMoreElements()) {
    String name = en.nextElement();
    FileConnection tmp = (FileConnection) Connector.open(
        "file:///SomeDirectory/" + name);
    tmp.delete();
    tmp.close();
}

Exception handling, the correct processing of resources (using finally) is left as an exercise for the reader :-)

+9
source

File.list() File.listFiles(), . File.delete(), . File.delete().

, , , , .

0

Source: https://habr.com/ru/post/1790880/


All Articles