Solusi

Berikut ini contoh kode program untuk menghapus file dari file system yang saya tulis.

public static void deleteFile(String path) {
        if (path.startsWith("file://")) {
            // do nothing
        } else if (!path.startsWith("/"))
            path = "file:///" + path;
        else if (path.startsWith("//"))
            path = "file:/" + path;
        else
            path = "file://" + path;
 
        try {
            FileConnection file = (FileConnection) Connector.open(path,
                    Connector.READ_WRITE);
            if (file.exists()) {
                file.setWritable(true);
                file.delete();
            }
            file.close();
        } catch (IOException ex) {
            System.out.println("File cannot be deleted");
        }
}

September 27, 2011

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Mobile and Web Analytics