×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    94

    How to write into a text file in J2ME?

    Hi to All,

    This is Urgent.I have to create a text file in drive and write/delete data into it.
    when I am trying to write in a already created file. It goes stuck in connection line.

    Here's my code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.io.*;
    import javax.microedition.io.*;

    public class FileConnection extends MIDlet implements CommandListener {
    private Command exit, start;
    private Display display;
    private Form form;
    public FileConnection ()
    {
    display = Display.getDisplay(this);
    exit = new Command("Exit", Command.EXIT, 1);
    start = new Command("Start", Command.EXIT, 1);
    form = new Form("Write To File");
    form.addCommand(exit);
    form.addCommand(start);
    form.setCommandListener(this);
    }
    public void startApp() throws MIDletStateChangeException
    {
    display.setCurrent(form);
    }
    public void pauseApp()
    {
    }
    public void destroyApp(boolean unconditional)
    {
    }
    public void commandAction(Command command, Displayable displayable)
    {
    if (command == exit)
    {
    destroyApp(false);
    notifyDestroyed();
    }
    else if (command == start)
    {
    try
    {

    OutputConnection connection = (OutputConnection) Connector.open("file:///c:/myfile.txt", Connector.WRITE );
    OutputStream out = connection.openOutputStream();
    PrintStream output = new PrintStream( out );
    output.println( "This is a test." );
    out.close();
    connection.close();

    }

    catch(Exception e)
    {
    System.out.println("file connection:="+e);
    }
    }
    }
    }

    Please advice.
    Regards,
    Juned Ahmed

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: How to write into a text file in J2ME?

    You should use FCA - JSR-75, File connnection API's for this.

    ref to thread for code example:
    http://discussion.forum.nokia.com/fo...d.php?t=198713

    thanks,
    ~Amitabh

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    94

    Re: How to write into a text file in J2ME?

    Thanks for ur reply
    Regards,
    Juned Ahmed

Similar Threads

  1. Reading text from a text file in j2me
    By baaluaanand in forum Mobile Java General
    Replies: 4
    Last Post: 2010-05-20, 03:13
  2. How to read and write a binary file in J2ME
    By kamalakshan in forum Mobile Java General
    Replies: 6
    Last Post: 2008-02-29, 11:28
  3. how to write in a text file using J2me
    By b7b7 in forum Mobile Java Tools & SDKs
    Replies: 2
    Last Post: 2007-07-01, 11:36
  4. Contacts fields order??
    By timatima in forum Symbian
    Replies: 1
    Last Post: 2007-06-08, 13:51
  5. Write file in 3rd generation with j2me
    By loay980 in forum Mobile Java Networking & Messaging & Security
    Replies: 13
    Last Post: 2006-03-30, 08:03

Posting Permissions

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