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
nikita18
Posts: 144
Registered: ‎08-18-2012
My Device: Blackberry Curve 8520
My Carrier: Vodafone

File delete shows Exception: The file is currently in use.

Hello everyone,

I have an app where I create an image file, upload it and then delete it. The first two work fine but when I try to delete the file, it shows an Exception that the File is currently in use. How can I delete this file. Can somebody help.

Thanks you.

Please use plain text.
Developer
nikita18
Posts: 144
Registered: ‎08-18-2012
My Device: Blackberry Curve 8520
My Carrier: Vodafone

Re: File delete shows Exception: The file is currently in use.

[ Edited ]

Here is my code:

 

try{
		FileConnection f=null;
			 OutputStream out=null;
			 filename=getCurrDateTime();	  
			   
					f=(FileConnection) Connector.open("file:///store/home/user/_"+filename+".jpg",Connector.READ_WRITE);			
 					f.create();
					
					out=f.openOutputStream();			
					out.write(getBytes());    
			    	out.close();	   	
			    	
			    StringBuffer connectionStr=new StringBuffer("http://www.myserver.com/bb/upload.php);		 
				connectionStr.append(getString());	
					
				//upload image	
				sendImg(connectionStr.toString());	
					
				//delete file	
				f.delete();
				f.close();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					System.out.println("====Exception: "+e.getMessage());
				}

 

Please use plain text.
Developer
simon_hain
Posts: 15,846
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: File delete shows Exception: The file is currently in use.

maybe you should wait a bit until you try to delete the file.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
nikita18
Posts: 144
Registered: ‎08-18-2012
My Device: Blackberry Curve 8520
My Carrier: Vodafone

Re: File delete shows Exception: The file is currently in use.

And how should I do that? When should I start deleting the file, till what time should I wait? 

Please use plain text.
Developer
nikita18
Posts: 144
Registered: ‎08-18-2012
My Device: Blackberry Curve 8520
My Carrier: Vodafone

Re: File delete shows Exception: The file is currently in use.

Now what I have done is, on the powerOff() event, I deleted the images I created. But I guess this is not an efficient method but it works. Can anybody suggest a better method? 

Please use plain text.
Developer
simon_hain
Posts: 15,846
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: File delete shows Exception: The file is currently in use.

poweroff may never be called, depending on the habits of the user.
my guess would be that a wait of 500ms or something would be more than enough, but thats just fishing in the dark.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
nikita18
Posts: 144
Registered: ‎08-18-2012
My Device: Blackberry Curve 8520
My Carrier: Vodafone

Re: File delete shows Exception: The file is currently in use.

Thanks for your reply, Simon. Yup I did it before. But I would like a method that could give me some sort of confirmation in this case.

Please use plain text.