×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Nov 2007
    Posts
    81

    FileConnection access denied

    here is the snippet of the code

    Code:
    public static void readWriteCrypto(RC4 rc4, final String path, int size, final String operation,
    			String [] retVal){
    		try{
    			FileConnection fileConnection = (FileConnection) Connector.open(path, Connector.READ_WRITE);
    			if(!fileConnection.exists()){
    				throw new IOException("File does not exist");
    			}
    			else{
    				InputStream inputStream = fileConnection.openInputStream();
    				byte [] messageBytes;
    				byte [] cryptoBytes;
    				if(size == 0){
    					size = (int) fileConnection.fileSize();
    				}
    				
    				messageBytes = new byte[size];
    				inputStream.read(messageBytes, 0, size);
    				
    				inputStream.close();
    				
    				OutputStream outputStream = fileConnection.openOutputStream();
    				
    				if(operation.equalsIgnoreCase("encrypt")){
    					cryptoBytes = rc4.encryptToBytes(messageBytes);
    					outputStream.write(cryptoBytes, 0, size);
    					outputStream.close();
    					fileConnection.close();
    					retVal[0] = "true";
    				}
    				else if(operation.equalsIgnoreCase("decrypt")){
    					cryptoBytes = rc4.decryptToBytes(messageBytes);
    					outputStream.write(cryptoBytes, 0, size);
    					outputStream.close();
    					fileConnection.close();
    					retVal[0] = "true";
    				}
    				else{
    					outputStream.close();
    					fileConnection.close();
    					retVal[0] = "false";
    				}
    			}
    		}
    		catch(Exception e){
    			retVal[0] = e.getMessage();
    		}
    	}

    when i run it, an Exception occurs. the message from
    Code:
    e.getMessage();
    is "Access Denied".

  2. #2
    Super Contributor
    Join Date
    Apr 2009
    Posts
    572

    Re: FileConnection access denied

    hi your code seems to look ok I think you haven't set the property of emulator in properties page make necessary changes
    Regards,
    Saurabh

  3. #3
    Regular Contributor
    Join Date
    Nov 2007
    Posts
    81

    Re: FileConnection access denied

    Quote Originally Posted by ingsaurabh View Post
    hi your code seems to look ok I think you haven't set the property of emulator in properties page make necessary changes
    uh... how do i set the properties in the manifest file so that i can do this? i read this somewhere, but i dont know the specifics.

    in addition to the usual stuff in the .MF, i have included this:

    Code:
    MIDlet-Permissions: javax.microedition.io.Connector.file.read,javax.microedition.io.Connector.file.write
    but it still does not work...
    Last edited by thechameleon; 2009-08-12 at 07:31.

  4. #4
    Super Contributor
    Join Date
    Apr 2009
    Posts
    572

    Re: FileConnection access denied

    hi

    I dont know about other ide but I work in netbeans so here is the method for that

    in project pane rt click your project>> properties

    in left pane i.e. category choose platform

    in right pane i.e. optional packages check those you wanted (File connection and pim API)

    and finall click Ok

    Thats all
    Last edited by ingsaurabh; 2009-08-12 at 08:42.
    Regards,
    Saurabh

  5. #5
    Regular Contributor
    Join Date
    Nov 2007
    Posts
    81

    Re: FileConnection access denied

    Quote Originally Posted by ingsaurabh View Post
    hi

    I dont know about other ide but I work in netbeans so here is the method for that

    in project pane rt click your project>> properties

    in left pane i.e. category choose platform

    in right pane i.e. optional packages check those you wanted (File connection and pim API)

    and finall click Ok

    Thats all

    hmmm... did u do operations that overwrite the contents of your file? for example, read the plaintext file, then write the cipher over the original file so that no new file has been created? or is there a function that u know can achieve this, other than FileConnection?

    from wat i know... only JSR75 is required for FileConnection to work. i have enabled it and set the permissions to enable Connector to read and write. but i still get the "Access Denied" Exception.

  6. #6
    Super Contributor
    Join Date
    Apr 2009
    Posts
    572

    Re: FileConnection access denied

    that's very strange BTW I haven't tried file connection but are you sure that file exist in file system and if exist try to change the attributes of file from file system of your OS to read write , etc hope that this works
    Regards,
    Saurabh

  7. #7
    Regular Contributor
    Join Date
    Nov 2007
    Posts
    81

    Re: FileConnection access denied

    thanks for the help.

    the problem's solved... after rewriting the code, cleaning up the class files and then rebuild the whole jar.
    Last edited by thechameleon; 2009-08-13 at 18:47.

Similar Threads

  1. FileConnection Access denied
    By belzi in forum Mobile Java General
    Replies: 2
    Last Post: 2008-09-07, 11:49
  2. Denied access to C memory
    By jmv_ in forum PC Suite API and PC Connectivity SDK
    Replies: 0
    Last Post: 2007-10-09, 13:24
  3. access denied new memory card
    By mike230632 in forum General Development Questions
    Replies: 1
    Last Post: 2007-10-08, 16:33
  4. Java FileConnection Optional Package 1.0 (JSR 75)
    By thecrowi in forum Mobile Java General
    Replies: 0
    Last Post: 2004-09-24, 08:29
  5. Access Denied Error and a DBMS 2 Panic
    By kiranpuranik in forum Symbian
    Replies: 0
    Last Post: 2004-05-13, 11:18

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×