⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 writereadexample.java

📁 利用J2ME编制的记录存储体的读写过程实例
💻 JAVA
字号:
import javax.microedition.rms.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
public class WriteReadExample extends MIDlet implements CommandListener
{
  private Display display;
  private Alert alert;
  private Form form;
  private Command exit;
  private Command start;
  private RecordStore recordstore=null;
  public WriteReadExample()
  {   
    display=Display.getDisplay(this);    
    exit=new Command("Exit",Command.SCREEN,1);
    start=new Command("Start",Command.SCREEN,1);    
    form=new Form("Record");     
    form.addCommand(exit);
    form.addCommand(start);
    form.setCommandListener(this);   
  }
  public void startApp()
  {
    display.setCurrent(form);
  }
  public void pauseApp()
  {
  }
  public void destroyApp(boolean unconditional) 
  {
  }
  public void commandAction(Command command,Displayable displayable)
  {
    if (command==exit)
    {     
      destroyApp(true);
      notifyDestroyed();    
     }
    else if (command==start)
    {
      try
      {
        recordstore=RecordStore.openRecordStore("myRecordStroe",true);
      }
      catch (Exception error)
      {
        alert=new Alert("Error Creating",error.toString(),null,AlertType.WARNING);
        alert.setTimeout(Alert.FOREVER);
        display.setCurrent(alert);
      }
      try
      {
        String outputData="First Record";
        byte[] byteOutputData=outputData.getBytes();
        recordstore.addRecord(byteOutputData,0,byteOutputData.length);
      }
      catch (Exception error)
      {
        alert=new Alert("Error Closing",error.toString(),null,AlertType.WARNING);
        alert.setTimeout(Alert.FOREVER);
        display.setCurrent(alert);
      }
      if (RecordStore.listRecordStores()!=null)
      {
        try
        {
          RecordStore.deleteRecordStore("myRecordStore");
        }
        catch (Exception error)
        {
          alert=new Alert("Erroe Removing",error.toString(),null,AlertType.WARNING);
          alert.setTimeout(Alert.FOREVER);
          display.setCurrent(alert);
        }
      }
    }
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -