×

Discussion Board

Results 1 to 7 of 7

Thread: Files Question

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    Somewhere, England
    Posts
    15

    Files Question

    Hi again!

    I'm making an application that'll run on a nokia 6680 and i'm trying to solve a little problem i have and i've come across a question that i cant seem to find the answer to....

    Can you write to and read from files using a MIDlet? I know you can do that in java cos it was part of my course, but i cant seem to find a definative yes or no answer on the internet!

    Basically i'd like to be able to write a couple of strings to a text file using one midlet and then read them using another that is in the same midlet suite. I've got a feeling it is possible using the microedition.io.file API, but i cant seem to find enough about it to convince myself either way.....

    can anyone help me by letting me know if this is possible and if so how i'd go about it?

    thanks!
    Andy

  2. #2
    Super Contributor
    Join Date
    Mar 2006
    Location
    Phoenix, AZ. USA
    Posts
    556

    Re: Files Question

    yes, it's possible, if device supports jsr-75 PDA profile, which in turn, provides api's for accessing the phone book, as well as a fileconnection api, i'll find you a link and small code example.

    you might look up, whether or not the 6680 supports jsr-75, i am not sure...
    Jason Glass
    http://IChiBanComputers.Com

  3. #3
    Super Contributor
    Join Date
    Mar 2006
    Location
    Phoenix, AZ. USA
    Posts
    556

    Re: Files Question

    a nokia example, of course, it is zipped and requires download...
    http://www.forum.nokia.com/info/sw.n..._v1_1.zip.html

    a example...
    http://developer.sonyericsson.com/si...nectionapi.jsp

    api info...
    http://www.j2medev.com/api/fileconne...e-summary.html
    http://java.sun.com/j2me/docs/wtk2.2...html/pdap.html

    little code...

    To check if the the FileConnection API is implemented use the:
    System.getProperty("microedition.io.file.FileConnection.version");
    This should return "1.0" if it is implemented.

    To create a FileConnection, use the Connector factory's open method which returns a Connection:

    Connector.open(string URL);

    Valid URLs:

    For internal memory "file://localhost/c:/" or "file:///c:/".
    For memory card "file://localhost/c:/" or "file:///e:/

    So when accessing the other directory in the internal memory, create a FileConnection object using the URL below:
    FileConnection fc = (FileConnection)Connector.open("file:///c:/");

    To list the content of a directory that your FileConnection is pointing to:
    Enumeration e = fc.list();
    while (e.hasMoreElements()) {
    System.out.println(((String)e.nextElement()));
    }

    The FileSystemRegistry has the static method listRoots() to list the available and supported mounted roots on the device. The list is returned as an Enumeration :
    Enumeration e = FileSystemRegistry.listRoots();
    while (e.hasMoreElements()) {
    String rootName = (String)e.nextElement();
    System.out.println("mounted root:"+rootName);
    }

    File I/O
    If you are used to the GCF connection framework, you will be very familiar with reading from files and writing to files. To write to a file you need to get an OutputStream from the FileConnection object that points to the existing file:
    OutputStream os = fc.openOutputStream()
    os.write(new String("hello").getBytes());
    os.close();

    Or you can use the DataOutputStream to write primitive Java datatypes to a file:
    int i = 1234;
    DataOutputStream ds = fc. openDataOutputStream();
    ds.writeInt(i);
    ds.close();

    To read from a file you get the InputStream or a DataInputStream from a FileConnection object that is pointing to the existing file:
    byte[] b = new byte[1024];
    InputStream is = fc.openInputStream();
    is.read(b);
    is.close();
    Jason Glass
    http://IChiBanComputers.Com

  4. #4
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429

    Re: Files Question

    Andy,
    Here in this link I have already posted some helpful links to start up with FileConnection API
    Please check this link http://discussion.forum.nokia.com/fo...ad.php?t=57674

    6680 do support FileConnection and PIM API (JSR-75) Please check this link http://www.forum.nokia.com/main/0,,0...tml?model=6680

    You could see the API support of different devices in the link http://www.forum.nokia.com/main/0,6566,150,00.html

    Also I would like to suggest please search the Forum before making a post, so that you could find some quick answers.

    Regards
    Gopal

  5. #5
    Registered User
    Join Date
    Mar 2006
    Location
    Somewhere, England
    Posts
    15

    Re: Files Question

    cheers for the help guys! sorry gopal, i did search and couldnt find any definative yes or no when i searched for reading and writing files, but i'll remember to do a more thorough search in the future!

    cheers again!

  6. #6
    Super Contributor
    Join Date
    Mar 2006
    Location
    Phoenix, AZ. USA
    Posts
    556

    Re: Files Question

    good luck! I dont mind your posts!
    Jason Glass
    http://IChiBanComputers.Com

  7. #7
    Registered User
    Join Date
    Mar 2006
    Location
    Somewhere, England
    Posts
    15

    Re: Files Question

    EDITED----- ignore this

Similar Threads

  1. a simple question on sound files
    By girish sharma in forum Symbian Media (Closed)
    Replies: 4
    Last Post: 2005-02-02, 08:13
  2. Question about SISAR or making SIS files.
    By Hell255 in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2004-03-23, 07:59
  3. #define header files question (n00b)
    By advocatee in forum Symbian
    Replies: 1
    Last Post: 2003-06-27, 07:53
  4. newbi question: building apps with rss files
    By mrabie in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2002-10-14, 10:46

Posting Permissions

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