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: 207
Registered: ‎07-31-2009
My Device: Not Specified
Accepted Solution

IOException Error code -25

Hi, 

I have been trying to delete a file using FileConnections's delete() method and it keeps throwing IOException Error code 25.

I am pretty sure i am closing all instances of the fileconnection object after their use..Any help??

 

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Developer
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: IOException Error code -25

Is there any other way to delete a file or can we force delete on a file...??

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Developer
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: IOException Error code -25

Here's the code : 

 

 

try {
	    		FileConnection fcon= (FileConnection)Connector.open("fileName",Connector.READ_WRITE);
				if(fcon.exists()) 
				{ 
					fcon.delete();	
				}
			} 
	
		catch (IOException e)
		    {
			Dialog.alert("Delete Error : "+e.getMessage());   }

 

The exception it throws is  " The file is currently in use" ..

 

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: IOException Error code -25

What is your testing environment?


Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: IOException Error code -25

[ Edited ]

Hi,

I using Blackberry Plugin for eclipse version 1.0.0.67  and for debugging am using Blackberry 9300 simulator. Eclipse  Version: 3.4.1and JDE Component 4.5.0.16

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Developer
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: IOException Error code -25

[ Edited ]

Is there any chance that calling close might not always close all streams?? Or is there a way to ensure that all streams do close..

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: IOException Error code -25

There are some cases teh streams not closed. Might have thrown exception and the file delete might not have excecuted.


Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: IOException Error code -25

Problem Solved :

 

I have been using the following code from the knowledge base article here  for parsing Xml from a file :

 

 

 conn=(StreamConnection)Connector.open
                  ("http://localhost:8000/content/test.xml");
                //next few lines creates variables to open a
                //stream, parse it, collect XML data and
                //extract the data which is required.
                //In this case they are elements,
                //node and the values of an element
                DocumentBuilderFactory docBuilderFactory
                  = DocumentBuilderFactory. newInstance(); 
                DocumentBuilder docBuilder
                  = docBuilderFactory.newDocumentBuilder();
                docBuilder.isValidating();
                doc = docBuilder.parse(conn.openInputStream());
                doc.getDocumentElement ().normalize ();
                NodeList list=doc.getElementsByTagName("*");

This is the same example that people follow in the forum (Something that i have noticed , not necessarily production code that people use but neverthless).

 

And people normally would do a conn.close() after parsing it(code in red ).

This i thought would close all active connections. But it seems it really does'nt.

And so a simple solution is to do this..

 

 

InputStream stream= conn.openInputStream();
 doc = docBuilder.parse(stream);
 stream.close();
  conn.close();

 

 This makes sure that all streams do close. 

 

 

 

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.