Gemalto is now part of the Thales Group, find out more.

You are here

Delete jar file in FFS with FileConnection API | Thales IoT Developer Community

August 24, 2017 - 9:01am, 2594 views

Hello,

I want to delete a jar file by using FileConnection API (JSR75).

I want to check if file exists in FFS by using exists() method and then delete if exists.

There are 2 situations that causes different exceptions in operation.

1. If I open jar file with READ_WRITE ****, open method throws security exception that says:

java.lang.SecurityException: Application not authorized to access the restricted API:javax.microedition.io.Connector.file.manufacturer

2. If I open jar file with WRITE ****, open method passes successfully but exists() method throws IllegalModeException which says:

 javax.microedition.io.file.IllegalModeException: Connection is write only

Is there a proper way of deleting a jar file with checking file existency without getting exception?

My simple code block is below:

String jarFile = "file:///a:/xyz.jar";

FileConnection fc = null;

try {

       //fc = (FileConnection) Connector.open(jarFile, Connector.WRITE);

      fc = (FileConnection) Connector.open(jarFile, Connector.READ_WRITE);

       if(fc.exists()) {

              fc.delete();

              fc.close();

       }

} catch (Exception e) {

e.printStackTrace();

}