import java.io.*; import javax.microedition.io.*; import javax.microedition.lcdui.*; import javax.microedition.io.file.*; import javax.microedition.midlet.MIDlet; public class Main extends MIDlet implements CommandListener { private Display display; private Form form = new Form("Data Output"); private Command submit = new Command("OK", Command.OK, 1); private Command exit = new Command("Exit", Command.EXIT, 1); private TextField text, path; public Main() { display = Display.getDisplay(this); text = new TextField("Text UTF:", "", 30, TextField.ANY); path = new TextField("Path:", "/E:/test.txt", 30, TextField.ANY); form.addCommand(exit); form.addCommand(submit); form.append(text); form.append(path); form.setCommandListener(this); } public void startApp() { display.setCurrent(form); } public void writeScreen() { Form form = new Form("WRITTEN"); form.append("Path:\n" + path.getString()); form.append("Text:\n" + text.getString()); form.addCommand(exit); form.setCommandListener(this); display.setCurrent(form); } public void writeUTF(String path, String str) { try { FileConnection fc = (FileConnection) Connector.open("file://" + path, Connector.WRITE); fc.create(); DataOutputStream dos = fc.openDataOutputStream(); dos.writeUTF(str); dos.close(); fc.close(); } catch(Exception ex) { } } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command command, Displayable displayable) { if (command == submit) { writeUTF(path.getString(), text.getString()); writeScreen(); form.removeCommand(submit); } else if (command == exit) { destroyApp(false); notifyDestroyed(); } } }