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
Trusted Contributor
Posts: 184
Registered: ‎11-26-2010
My Device: Not Specified
Accepted Solution

FileConnection -Controlled Access Exception

[ Edited ]

public class CreateFileApp extends Application 

{    public static void main(String[] args)    

{        CreateFileApp app = new CreateFileApp();       

app.setAcceptEvents(false);       

try         {             

FileConnection fc = (FileConnection)Connector.open("file:///store/home/user/newfile.txt");             

if (!fc.exists())             // CONTROLLED ACCESS EXCEPTION

{                 

fc.mkdir();              

}             

fc.close();         

}         catch (IOException ioe)        

 {            System.out.println(ioe.getMessage() );         

}   

 

}

I am trying to run this sample application found in BB Document;

When I tried debugging the application it is throwing controlled access exception at the above hightd line.

In simulator it is popping up a error message Applciation Terminated: File system has been denied the "Files " permission.

Any help is welcomed. Smiley Happy

 

A Y

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: FileConnection -Controlled Access Exception

[ Edited ]

Hi avi_yach,

 

In the simulator settings, there is an check-box to use the computer as the file system. you should check this option.

 

In your device, try changing the application permissions.

 

E. 

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: FileConnection -Controlled Access Exception

The "store/home/user" directory is the internal memory so there is no need to check the box to use the computer as the file system. Check to make sure that security is disabled in the simulator.
Developer
Posts: 285
Registered: ‎08-26-2011
My Device: 9900
My Carrier: Not Specified

Re: FileConnection -Controlled Access Exception

When you get controlAccessException then It is better to clean and restart/only restart the simulator. You should not get this exception in device because you are again and again debugging in simlator. This is not  the case in device. That's why.

 

==========================================================================================

 

Feel Free to click THUMB(LIKE) symbol.

=================================================================================
Feel free to click LIKE button if the solution helps you;
--
Regards,

ALI SHAIK.
Trusted Contributor
Posts: 184
Registered: ‎11-26-2010
My Device: Not Specified

Re: FileConnection -Controlled Access Exception

Hello maadani, thanks for your reply, I have enabled this option "using computer as file system". I will share the procedure which I followed, I created a folder called SDCard in my private directory and in simulator memory settings I matched the memory to SDCard on the H folder.

 

A Y

Trusted Contributor
Posts: 184
Registered: ‎11-26-2010
My Device: Not Specified

Re: FileConnection -Controlled Access Exception

Hello CMY, thanks for your reply, can you suggest me how to change the simulator settings? In couple of posts they have suggested to disable simulator security settings. Is it possible?

 

A Y 

Trusted Contributor
Posts: 184
Registered: ‎11-26-2010
My Device: Not Specified

Re: FileConnection -Controlled Access Exception

[ Edited ]

Thanks for your reply Alishaik, I tried this, but no luck Smiley Sad

 

A Y

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: FileConnection -Controlled Access Exception

[ Edited ]

Another couple of things that might help:

 

1. Try to create a directory under "file:///store/home/user/" and create your file in the new directory.

 

2. Try create your file with just the file name: "FileConnection)Connector.open(file_name.txt);"

 

3. Try using a parameter in the open function: "FileConnection)Connector.open(file_name.txt,Connector.READ_WRITE);"

 

E.

Developer
Posts: 285
Registered: ‎08-26-2011
My Device: 9900
My Carrier: Not Specified

Re: FileConnection -Controlled Access Exception

You are checking file exist or not. And if not exists then you are creating a Directory not a file.

try
{
	FileConnection fc=(FileConnection)Connector.open(PATH);        	
	 if(fc.exists())
          		fc.truncate(0);
 	else
         		 fc.create();//here you are creating a directory instead or file.
	//Write what ever you want;
 	fc.close();
}

 ===============================================================================

Feel Free to click THUMB(LIKE) button.

=================================================================================
Feel free to click LIKE button if the solution helps you;
--
Regards,

ALI SHAIK.
Highlighted
Trusted Contributor
Posts: 184
Registered: ‎11-26-2010
My Device: Not Specified

Re: FileConnection -Controlled Access Exception

[ Edited ]

@all : after long slogging I realised that application not having permission to access Files can be a reason for this error. This can be avoided by (BlackBerry 9550)settings>Application>menu>edit default permission>connections>allow

 

 

 

any other alternative is also welcomed Smiley Happy