×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Nov 2010
    Location
    Egypt,Mansoura
    Posts
    80

    i wanna a modification in that code

    i get that code from wiki to write what i write in TextBox in file with extension txt

    Code:
    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();
        }
    }
    But i wanna User To Defind the path Not Only on Photos as In that Code

    thanks alot,
    Let The Impossible Happen!!!

  2. #2
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: i wanna a modification in that code

    regarding where you are allowed to write a file with the jsr 75, you don't always have a lot of options, and it depends on the device, too.
    "fileconn.dir.photos" is where you are most likely to be allowed to write.
    check nokia guide for file connection api : http://www.forum.nokia.com/info/sw.n..._0_en.zip.html

Similar Threads

  1. do anyone have some j2me code to geotag, i wanna test it in N95
    By sweehoe87 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2010-04-12, 06:53
  2. Modification of current functions
    By Ronald-8 in forum Mobile Java General
    Replies: 0
    Last Post: 2006-01-19, 01:21
  3. bmpmanip modification
    By yfho in forum Symbian
    Replies: 0
    Last Post: 2003-08-19, 11:02
  4. Carkit modification?
    By mgi78 in forum General Development Questions
    Replies: 0
    Last Post: 2003-05-20, 06:54
  5. PNG modification
    By LY in forum Mobile Java General
    Replies: 0
    Last Post: 2002-12-13, 07:18

Posting Permissions

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