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

📄 persistantdata.java~1~

📁 java 的手机通讯录程序
💻 JAVA~1~
字号:
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
public class PersistantData
{
  private String name, telno, recno;
  public static RecordStore recordStore = null;
  public void openRecStore(String dataStoreName)
  {
    try
    {
      recordStore = RecordStore.openRecordStore(dataStoreName, true);
      System.out.println("datastore name: " + recordStore.getName() +
                         "  version no: " + recordStore.getVersion());
    }
    catch (RecordStoreException e)
    {
      e.printStackTrace();
    }
  }
  public void closeRecStore()
  {
    try
    {
      recordStore.closeRecordStore();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  public void addNewRecord(String record)
  {
    byte[] rec = record.getBytes();
    try
    {
      recordStore.addRecord(rec, 0, rec.length);
      readRecordStore();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  public boolean deleteRecord(int rec)
  {
    boolean flag = false;
    try
    {
      recordStore.deleteRecord(rec);
      flag = true;
      return flag;
    }
    catch (Exception e)
    {
      e.printStackTrace();
      return flag;
    }
  }
  public void editRecord(int id, byte[] bytearray, int bytearraylength)
  {
    try
    {
      recordStore.setRecord(id, bytearray, 0, bytearraylength);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  public String[] readRecordStore()
  {
    String table[] = null;

    try
    {
      int tablesize = recordStore.getNumRecords();
      table = new String[tablesize];
      int recordid;
      byte[] record = null;
      int i = 1;
      RecordEnumeration re = recordStore.enumerateRecords(null, null, false);
      while (re.hasNextElement())
      {
        recordid = re.nextRecordId();
        String res = new String(PersistantData.recordStore.getRecord(recordid));
        res += ";" + recordid;
        System.out.println("Record " + ":" + res);
        table[i - 1] = res;
        i++;
      }
      return table;
    }
    catch (Exception e)
    {
      e.printStackTrace();
      return table;
    }
  }
    public void deleteRecordStore(String store)
    {
      try
      {
        RecordStore.deleteRecordStore(store);
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
    }
    public RecordEnumeration enumerate() throws RecordStoreNotOpenException
    {
      return recordStore.enumerateRecords(null, null, true);
    }
    private void parse(String data)
    {
      int index1 = data.indexOf(";");
      int index2 = data.indexOf(";", index1 + 1);
      name = data.substring(0, index1);
      telno = data.substring(index1 + 1, index2);
      recno = data.substring(index2 + 1);
    }
    public String getName(String record)
    {
      parse(record);
      return name;
    }
    public String getTelno(String record)
    {
      parse(record);
      return telno;
    }
    public String getRecno(String record)
    {
      parse(record);
      return recno;
    }
  }

⌨️ 快捷键说明

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