import java.io.DataOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import javax.microedition.io.Connector; import javax.microedition.io.file.FileConnection; import javax.microedition.lcdui.*; import javax.microedition.midlet.MIDlet; public class Main extends MIDlet implements CommandListener { public Display dsp; public Form form; public TextField tf; public Command next; public String str; public byte bytes[]; public int st; public void startApp() { dsp = Display.getDisplay(this); form = new Form(""); tf = new TextField("Строка", "Название карты", 99, TextField.ANY); next = new Command("Next", Command.OK, 1); form.append(tf); form.addCommand(next); form.setCommandListener(this); dsp.setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean flag) { } public void commandAction(Command c, Displayable d) { if (c == next) { Form f = new Form("Результат"); st = tf.getString().length(); str = tf.getString(); try { bytes = str.getBytes("UTF-16"); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } String file_string = ""; for (int i = 0; i < bytes.length; i++) { file_string += (char) bytes[i]; } f.append("" + st + file_string); try { save(1); } catch (IOException ex) { ex.printStackTrace(); } dsp.setCurrent(f); } } public void save(int numt) throws IOException { for (int i0 = 0; i0 < numt; i0++) { FileConnection fileconnection = (FileConnection) Connector.open("file:///" + "root/test.ntv", 3); if (fileconnection.exists()) { fileconnection.delete(); } fileconnection.create(); DataOutputStream out = fileconnection.openDataOutputStream(); //out.writeByte(tf.getString().length() * 2);// out.write(bytes); out.close();// закриваем fileconnection.close();// закриваем } } }