×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    5

    Unable to write files with FileConnection api

    Hello guys,i'm trying to write a String on a file,but there is no way i can get it done so far. I give you the code that i'm using so you can take a look:
    Code:
     FileConnection connection = (FileConnection)                     
              Connector.open("file:///E:/Images/log.txt", Connector.WRITE);
           if(!connection.exists())
               connection.create();
            OutputStream out = connection.openOutputStream();
            PrintStream output = new PrintStream( out );
            output.println( "This is a test." );
            out.close();
            connection.close();
    I'm testing it on my N95 8GB,once i run my midlet it asks me if i want to allow mobile-application to read user data then if i press yes apparently it seems all done but whether i check Images folder there isnt log.txt and even if i put log.txt manually in that folder and then i run the midlet,it doesn't write the string in the log.txt file. Of course i'm giving permissions in the jad file :
    Code:
    MIDlet-Permissions: javax.microedition.io.Connector.file.write, javax.microedition.io.Connector.file.read
    I cant really understand why this happens,does it have to do with signing the midlet? i hope not.
    Thank you guys.

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Unable to write files with FileConnection api

    Hi,

    No, it doesn't have to do with signing the midlet (only those "allow application to read user data" warnings do). There is a fully functional file writing example on the wiki:
    http://wiki.forum.nokia.com/index.ph...ile_in_Java_ME

    To make it simpler, here's what I used:
    Code:
    public void startApp() {
            try {
                String string="This is a test.";
                byte data[]=string.getBytes();
                FileConnection fconn=(FileConnection)Connector.open("file:///E:/Images/log.txt", Connector.READ_WRITE);
                if (!fconn.exists()) {
                    fconn.create();
                }
                OutputStream ops=fconn.openOutputStream();
                ops.write(data);
                ops.close();
                fconn.close();
            }
            catch (IOException ioe) {
                System.out.println("IOException: "+ioe.getMessage());
            }
            catch (SecurityException se) {
                System.out.println("Security exception:" + se.getMessage());
            }
    }

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    5

    Re: Unable to write files with FileConnection api

    thank you bodgan,in this way it works.

Similar Threads

  1. Unable to execute files for security reasons
    By bnvaikos in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 43
    Last Post: 2010-08-30, 06:54
  2. How to take file data in s String using Java and FileConnection API?
    By SanjayKhuntia in forum Mobile Java General
    Replies: 3
    Last Post: 2008-09-05, 15:22
  3. File creation without using FileConnection api
    By furrbie in forum Mobile Java General
    Replies: 2
    Last Post: 2007-05-15, 07:17
  4. Unable to execute files for security reasons
    By bnvaikos in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 1
    Last Post: 2006-11-30, 10:30
  5. Unable to load files into MIDP default phone
    By alan_stewart in forum Mobile Java General
    Replies: 0
    Last Post: 2003-03-03, 17:49

Posting Permissions

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