Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 298
Registered: ‎05-02-2010
My Device: Bold 9700
My Carrier: Verizon
Accepted Solution

Deleting a file returns "The file is currently in use."

I have the following method that I use to delete two files, when ran, I receive the message "The file is currently in use."

I believe my mistake is checking to see if the files exists before deleting them, however I've removed that condition and I receive the same message.

 

Any thoughts on how I can improve this function?

 

 

 

public final static void deleteAllDatabase() {
FileConnection fconn_temp = null;
FileConnection fconn = null;
try {
fconn_temp = (FileConnection) Connector
    .open(System.getProperty("fileconn.dir.memorycard")
        + resource.getString(CoffeeHouseResource.db_path)
        + resource
            .getString(CoffeeHouseResource.db_template_name),
        Connector.READ_WRITE);
fconn = (FileConnection) Connector.open(
    System.getProperty("fileconn.dir.memorycard")
        + resource.getString(CoffeeHouseResource.db_path)
        + resource.getString(CoffeeHouseResource.db_name),
    Connector.READ_WRITE);

if (fconn_temp.exists() && fconn.exists()) {
  fconn_temp.delete();
  fconn.delete();
}

} catch (IOException e) {
Logger.logEventError("deleteAllDatabase error: " + e.getMessage());
} finally {
if (fconn_temp != null) {
  try {
    fconn_temp.close();
  } catch (IOException e) {
  }
}
if (fconn != null) {
  try {
    fconn.close();
  } catch (IOException e) {
  }
}
}
}

 

 

--Todd

Windows 7 Enterprise 64-bit (6.1 Build 7600) | Java SE Runtime Environment (build 1.6.0_24-b07) | Eclipse Version: 3.6.2 [M20110210-1200] | BlackBerry Eclipse Plug-in: 1.3.0.201102031007-19 | Java Compiler level: 1.3 | Targeting devices running OS 5 | Simulators: JDE 5.0 packaged 9700, 9630, 9300
Highlighted
Regular Contributor
Posts: 64
Registered: ‎01-27-2011
My Device: Not Specified

Re: Deleting a file returns "The file is currently in use."

I believe its the common path names between both your file connections that are causing the error. Try using one file connection and delete each file individually rather than having two file connections and deleting them concurrently.

Developer
Posts: 298
Registered: ‎05-02-2010
My Device: Bold 9700
My Carrier: Verizon

Re: Deleting a file returns "The file is currently in use."

Thank you, I appreciate your help - kudos to you.

 

I just deleted the directory that contained both files instead of trying to delete each file independently.

--Todd

Windows 7 Enterprise 64-bit (6.1 Build 7600) | Java SE Runtime Environment (build 1.6.0_24-b07) | Eclipse Version: 3.6.2 [M20110210-1200] | BlackBerry Eclipse Plug-in: 1.3.0.201102031007-19 | Java Compiler level: 1.3 | Targeting devices running OS 5 | Simulators: JDE 5.0 packaged 9700, 9630, 9300