I am trying to create file using RMS. I couldn't use List Command to create a file using RMS. Can you suggest easier way to create a file using List.
import javax.microedition.midlet.*;
import javax.microedition.rms.*;
import javax.microedition.lcdui.*;
public class RmsNormal extends MIDlet implements CommandListener
{
private Display disp;
private Command exit;
private List list;
private Alert alert;
private RecordStore recordstore = null;
public RmsNormal()
{
disp = Display.getDisplay(this);
exit = new Command("Exit", Command.EXIT, 1);
list = new List("Menu", List.IMPLICIT);
list.append("Create", null);
list.append("Write", null);
list.addCommand(exit);
list.setCommandListener(this);
}
protected void startApp()
{
disp.setCurrent(list);
}
protected void pauseApp()
{
}
protected void destroyApp(boolean uncond)
{
}
public void commandAction(Command cmd, Displayable display)
{
if(cmd == List.SELECT_COMMAND)
{
String selection = list.getString(list.getSelectedIndex());
// couldn't get idea to use List Command to Create File
try
{
recordstore = RecordStore.openRecordStore("RecorStore", true);
alert = new Alert("File Created", null, null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
disp.setCurrent(alert);
}
catch (Exception error)
{
alert = new Alert("Error Removing", error.toString(), null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
disp.setCurrent(alert);
}
try
{
String outputData = "My";
byte[] byteOutputData = outputData.getBytes();
recordstore.addRecord(byteOutputData, 0, byteOutputData.length);
}
catch (Exception error)
{
alert = new Alert("Alert", error.toString(), null, AlertType.WARNING);
alert.setTimeout(Alert.FOREVER);
disp.setCurrent(alert);
}
}
else if (cmd == exit)
{
destroyApp(true);
notifyDestroyed();
}
}
}