import java.io.*; import javax.microedition.rms.*; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class Head extends MIDlet implements CommandListener { Form form; TextField tf; Command input,output; Display dsp; static final String DBNAME = "rmsDB"; String write; public void startApp() { dsp = Display.getDisplay(this); form = new Form("RmsTest"); tf = new TextField("Строка для записи","xxxxxx",999,TextField.ANY); input = new Command("input",Command.OK,1); output = new Command("output",Command.BACK,2); form.append(tf); form.addCommand(input); form.addCommand(output); form.setCommandListener(this); dsp.setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command command, Displayable displayable) { if(command == input) {load(); form.append(write);} if(command == output) {store(tf.getString());} } public void store(String write) { RecordStore recordStore = null; try { recordStore = RecordStore.openRecordStore (DBNAME, true); ByteArrayOutputStream baos = new ByteArrayOutputStream (); DataOutputStream dos = new DataOutputStream (baos); dos.writeUTF(write); byte[] record = baos.toByteArray(); recordStore.addRecord (record, 0, record.length); } catch (Exception e) { System.out.println("Exception: " + e); } System.gc(); } public void load() { try { RecordStore recordStore = RecordStore.openRecordStore (DBNAME, false); byte[] record = recordStore.getRecord(1); ByteArrayInputStream bais = new ByteArrayInputStream (record); DataInputStream dis = new DataInputStream (bais); String write=""; write = dis.readUTF(); } catch (Exception e) { System.out.println ("Exception in loading data: " + e); } System.gc(); } }