×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Regular Contributor
    Join Date
    Dec 2009
    Location
    Ghaziabad
    Posts
    244

    Question Can we open a textfile and write some data in J2me

    Hi all,


    I know about FileConnection api it will create textfile at some place in mobile. But what i want is to open a textfile and write some data to it .... using J2me

    Please Reply

  2. #2
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: Can we open a textfile and write some data in J2me

    hello good day !! can i create a rms using j2me can you please give me some codes on how to store data using textfile or rms ? i am a beginner in j2me

  3. #3
    Nokia Developer Champion
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,545

    Re: Can we open a textfile and write some data in J2me

    Quote Originally Posted by AnorEnaj2330 View Post
    hello good day !! can i create a rms using j2me can you please give me some codes on how to store data using textfile or rms ? i am a beginner in j2me
    Several RMS and FileConnection API examples in the wiki: http://www.developer.nokia.com/Commu.../Data_Articles

    Try those first.

  4. #4
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: Can we open a textfile and write some data in J2me

    what is the steps on how to create can you please give some codes ?

  5. #5
    Nokia Developer Expert
    Join Date
    May 2012
    Posts
    224

    Re: Can we open a textfile and write some data in J2me

    For storing data to a file, see wiki example How to write data to a file in Java ME

    For storing data to RMS, see wiki example How to store Data in RMS

  6. #6
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: Can we open a textfile and write some data in J2me

    hello sir good day ..

    my problem is how can i write in a textfile using j2me,and how can i create a textfile using j2me is this possible sir?
    can you please give me some code codes in creating textfile in j2me
    or sir i want to write in notepad using j2me . thank you so much

    GOd bless !!!

  7. #7
    Nokia Developer Champion
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,545

    Re: Can we open a textfile and write some data in J2me

    Quote Originally Posted by AnorEnaj2330 View Post
    hello sir good day ..

    my problem is how can i write in a textfile using j2me,and how can i create a textfile using j2me is this possible sir?
    can you please give me some code codes in creating textfile in j2me
    or sir i want to write in notepad using j2me . thank you so much

    GOd bless !!!
    The link in my reply #2 to the wiki examples for using JSR-72 are still valid.

    No access from J2ME to text notes stored by the built-in "Notepad" app.

  8. #8
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: Can we open a textfile and write some data in J2me

    hello sir good day again ..

    so it is not possible to write in a textfile using j2me sir .. so we cant create,open and write in a notepad ??

    what can we use in a possible way to store data ? maybe can we use XML sir ??

    base on the google you can read and write in a data using j2me so why it is not possible ?? thank you sir ..!!

    God Bless !! have a nice day !

  9. #9
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: Can we open a textfile and write some data in J2me

    [import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.file.*;
    import javax.microedition.io.*;
    import java.io.*;

    public class WriteMIDlet extends MIDlet implements CommandListener {
    private TextBox textbox;
    private String photos = "fileconn.dir.photos";
    private Command saveCommand;
    private Command exitCommand;
    private String path;

    public void startApp() {
    textbox = new TextBox("WriteMIDlet", "", 1000, TextField.ANY);
    saveCommand = new Command("Save", Command.SCREEN, 1);
    exitCommand = new Command("Exit", Command.EXIT, 1);
    textbox.addCommand(saveCommand);
    textbox.addCommand(exitCommand);
    textbox.setCommandListener(this);
    Display.getDisplay(this).setCurrent(textbox);
    path = System.getProperty(photos);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    private void saveFile(String path, String name) {
    try {
    String url = path + name;
    String string = textbox.getString();
    byte data[] = string.getBytes();
    FileConnection fconn = (FileConnection)Connector.open(url, 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());
    }
    }

    public void commandAction(Command c, Displayable d) {
    if (c == saveCommand) saveFile(path, "readme.txt");
    if (c == exitCommand) this.notifyDestroyed();
    }
    }][/QUOTE]

  10. #10
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: Can we open a textfile and write some data in J2me

    hello mr./ms. bandarap ..

    Good day !!!

    i'll try your code
    For storing data to a file, see wiki example How to write data to a file in Java ME

    its not working .. the textfile there the readme.txt it is declared in the codes or you must create it first? how it works ??
    how it saved in a textfile(Readme.txt) where should i save this should i save this in a folder inside j2me ??

    can you please give me some codes steps on how to create it .

    tnx
    God Bless !!

  11. #11
    Nokia Developer Champion
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,545

    Re: Can we open a textfile and write some data in J2me

    Quote Originally Posted by AnorEnaj2330 View Post

    so it is not possible to write in a textfile using j2me sir .. so we cant create,open and write in a notepad ??

    what can we use in a possible way to store data ? maybe can we use XML sir ??

    base on the google you can read and write in a data using j2me so why it is not possible ?? thank you sir ..!!

    God Bless !! have a nice day !
    Reading and writing text files is perfectly doable through JSR-75, FileConnection API. On J2ME phones the only question is which locations (folders, directories) you are allowed to do it from.

    However, when you referred to "notepad", I assumed you meant a Notepad app on the phone. At least in the case of Nokia's Series 40 and Symbian/S60 based phones, the Notepad/Notes app on those phones, do not save the notes in text files that are accessible by other applications directly. If by "notepad" you meant, e.g., the Notepad application on a Windows PC, to edit text files, then, yes, you can in J2ME create text files, and if you move/copy them to a PC, then the Notepad app there can also edit those files.

    See the FileConnection API examples in the wiki, as already suggested to you. E.g., the articles titled "How to write data to a file in Java ME", "Reading a text file line by line in Java ME", etc., show you all you need to know, besides what's also in the Java SDK documentation for JSR-75.

  12. #12
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: Can we open a textfile and write some data in J2me

    hello sir good day again

    sir I'm using nokia phone . then i have my application notes .sir is this possible that i can save data from that application .
    what is the file root sir in saving data from j2me recorstore to sdcard notes in my cp . i dont have notepad in my cellphone but i have my notes .
    can i save data from this application? sir all i want is when i click the button save the data will automatically save in notes in my cp application.

    can you please give me some codes sir im a beginner in java and i have my project . thank you sir have a nice day !

    God Bless !!

  13. #13
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: Can we open a textfile and write some data in J2me

    sir ..
    i have these codes ..

    private void genExport() {
    try


    {
    String fileName= "data.txt";
    OutputConnection connection = (OutputConnection)
    Connector.open("file:///root1/data.txt", Connector.WRITE );
    OutputStream out = connection.openOutputStream();
    PrintStream output = new PrintStream( out );


    output.println(e_series);
    output.println(e_Msurname);
    output.println(e_Mname);
    output.println(e_Bname);
    output.println(e_bday);
    output.println(e_address);
    output.println(e_phoneNum);
    output.println(e_bumo);
    output.println(e_fb);


    out.close();
    connection.close();
    Alert alert = new Alert("Completed","Data Written", null, null);
    alert.setTimeout(Alert.FOREVER);
    alert.setType(AlertType.ERROR);
    display.setCurrent(alert);
    }
    catch(ConnectionNotFoundException error)
    {
    Alert alert = new Alert(
    "Error", "Cannot access file.", null, null);
    alert.setTimeout(Alert.FOREVER);
    alert.setType(AlertType.ERROR);
    display.setCurrent(alert);
    }
    catch( IOException error )


    {

    Alert alert = new Alert("Error", error.toString(), null, null);
    alert.setTimeout(Alert.FOREVER);
    alert.setType(AlertType.ERROR);
    display.setCurrent(alert);

    }
    }


    sir where can i find this one

    Connector.open("file:///root1/data.txt", Connector.WRITE );


    sir thank you ..

  14. #14
    Nokia Developer Champion
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,545

    Re: Can we open a textfile and write some data in J2me


  15. #15
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: Can we open a textfile and write some data in J2me

    GOOD DAY ! sir this my new question ..

    how can i create a text file using j2me I'm already using it in my phone all i want is to save the data in notes application in my phone ..

    and how can i find the rootfile in mobile .

    because i have my save button then when i pressed it i want to save it automatically in notes application in my nokia phone..

    thank you sir godbless !!!

Similar Threads

  1. Replies: 1
    Last Post: 2009-06-01, 11:36
  2. Replies: 8
    Last Post: 2008-02-29, 12:32
  3. can we like sync operation in j2me with data cables?
    By premlathiya in forum Mobile Java General
    Replies: 4
    Last Post: 2006-09-07, 18:00
  4. can we write j2me application(using midp1.0) that blocks the calls
    By Rameshwari in forum Mobile Java General
    Replies: 2
    Last Post: 2006-06-08, 13:32
  5. How can I write an array into a textfile?
    By manu.20 in forum Symbian
    Replies: 1
    Last Post: 2005-05-25, 14:33

Posting Permissions

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