×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    11

    problems about creating files

    Hi:
    I want to create a file on the S60 emulator and my IDE is Eclipse 3.2.Here is my code:

    private void createfile()
    {
    try{
    FileConnection fc=(FileConnection)Connector.open("file:///C:/new.txt");
    if(!fc.exists()){
    fc.create();
    System.out.println("correct");
    }
    fc.close();

    }catch(IOException ioe){
    System.out.println("error happens");

    }
    }

    But error occurs:

    Exception in handleDisplayableEvent. Reason: SecurityException
    source is : javax.microedition.lcdui.List@191b191b
    p0 is : 16
    p1 is : 0
    p2 is : 0
    java.lang.SecurityException: Access denied
    at com.symbian.midp.io.protocol.file.FileConnectionImpl.open(Unknown Source)
    at com.symbian.midp.io.protocol.file.Protocol.openConnection(Unknown Source)
    at com.symbian.gcf.ProtocolBase.openConnection(ProtocolBase.java:72)
    at com.symbian.midp.io.protocol.file.Connection.createConnection(Unknown Source)
    at com.nokia.mj.impl.vmport.J9GcfConnectionBase.setParameters2(Unknown Source)
    at javax.microedition.io.Connector.open(Unknown Source)
    at javax.microedition.io.Connector.open(Unknown Source)
    at MobileFileBrowser.creatfile(Unknown Source)
    at MobileFileBrowser.commandAction(Unknown Source)
    at javax.microedition.lcdui.Displayable.callCommandAction(Displayable.java:164)
    at javax.microedition.lcdui.Displayable.commandEvent(Displayable.java:137)
    at javax.microedition.lcdui.Displayable.handleEvent(Displayable.java:179)
    at javax.microedition.lcdui.List.handleEvent(List.java:356)
    at javax.microedition.lcdui.Toolkit.handleDisplayableEvent(Toolkit.java:526)
    at com.symbian.lcdjava.lang.SystemExtensions._dispatchCallbacks(Native Method)
    at com.symbian.lcdjava.lang.SystemExtensions.dispatchCallbacks(SystemExtensions.java:35)
    at com.symbian.midp.runtime.KVMEventProcessor.run(KVMEventProcessor.java:23)


    COULD ANY ONE WHY THIS HAPPENS OR WHAT COULD I DO TO SOLVE THE PROBLEM?
    THANKS!

  2. #2
    Registered User
    Join Date
    Aug 2007
    Posts
    8

    Re: problems about creating files

    Hi,

    C: in S60 is READ ONLY. Thats the reason why you are not able to create files there.

    Try running the following code.

    Code:
                FileConnection conn = (FileConnection) Connector.open("file:///C:/",Connector.READ);
                if( !conn.canWrite() )  {
                    form.append("C:/ Read only\n");
                } else {
                    form.append("c: can  write\n");
                }
                
                conn.setFileConnection("data/");
                if( !conn.canWrite() )  {
                    form.append("c:/data/ Read only\n");
                } else {
                    form.append("c:/data/ can  write\n");
                }
    Result:
    c:/ can not write
    c:/data/ can write

    Better option would be to check if the directory you are in is writable before trying to create a file.

    CSB

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    11

    Re: problems about creating files

    Thanks for csbhushan's reply.
    I have changed the code to FileConnection fc=(FileConnection)Connector.open("file:///C:/Data/new.txt");
    But it still throws out an java.lang.SecurityException. So what could i do now or where should i create the file?Or just because the emulator can't create files?
    Hoping for your replies.
    Thanks in advance.
    Last edited by yeliya; 2008-04-13 at 15:25.

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    3

    Re: problems about creating files

    I'm having the same problem? found any solution?

  5. #5
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    89

    Arrow Re: problems about creating files

    Hi,

    Use the Code to write the File..

    try
    {
    String path = System.getProperty("fileconn.dir.photos");
    FileConnection fc = (FileConnection)Connector.open(path+"New.txt",Connector.READ_WRITE);

    // Create the file if it doesn't exist
    if (!fc.exists())
    {
    fc.create();
    }
    long memoryAvailable = fc.availableSize();
    OutputStream os=null;
    os = fc.openOutputStream();
    os.write(data_toWrite);
    os.flush();
    os.close();
    }
    catch (Exception e)
    {
    System.out.println("The Exception is="+e);
    }

    It's working fine on the emulator, but when u deploy on device then give the permission on device to write the data. If u not give the permission on device then device throws a Security exception.

    Thanks
    Osam

  6. #6
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: problems about creating files

    CHECK THE SUITE SETTINGS OF APPLICATION IN APP MANAGER.
    FOLLOW THE INSTRUCTIONS:
    APP MANAGER -> UR APPLICATION -> CLICK OPTIONS -> CLICK SUITE SETTINGS -> CHECK READ WRITE PERMISSIONS -> SET THEM TO ALLOW FROM NOT ALLOWED


    TRY AND REPLY..
    thanks,
    jitu_goldie..

    KEEP TRYING..

Similar Threads

  1. linking error
    By dakosurf in forum Symbian
    Replies: 1
    Last Post: 2008-03-27, 22:45
  2. Problems with audio files on 6600
    By Tronn in forum Audio
    Replies: 3
    Last Post: 2004-10-18, 08:22
  3. Problems with voice files on Nokia 6600
    By paultreadaway in forum Audio
    Replies: 6
    Last Post: 2004-05-19, 03:35
  4. Creating jar files from class files
    By bhandari in forum Mobile Java General
    Replies: 4
    Last Post: 2003-12-25, 13:53
  5. Creating sis files without full SDK?
    By Marw_Work in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2003-05-07, 11:06

Posting Permissions

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