- package phoneLeter;
- import java.util.Vector;
- import javax.microedition.rms.RecordEnumeration;
- import javax.microedition.rms.RecordStore;
- public class RMSope {
- private String storeName;
- private RecordStore rs;
- //得到记录集的名称
- public RMSope(String storeName)
- {
- this.storeName=storeName;
- }
- //打开记录集
- public void openRecordStore()
- {
- try
- {
- rs=RecordStore.openRecordStore(storeName,true);
- }
- catch(Exception ex)
- {
- ex.printStackTrace();
- }
- }
- //增加记录集
- public void addPhone(String name,String phone)
- {
- String info=name+":"+phone;
- byte[] b=info.getBytes();
- try
- {
- rs.addRecord(b,0,b.length);
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- //删除记录集
- public void deletePhone(String str)
- {
- int lastId=0;
- try
- {
- lastId=rs.getNextRecordID();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- for(int i=1;i<lastId;i++)
- {
- try
- {
- byte[] b=rs.getRecord(i);
- String recordStr=new String(b);
- if(recordStr.equals(str))
- {
- rs.deleteRecord(i);
- }
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- }
- //获取所有记录集
- public Vector getAllPhone()
- {
- Vector v=new Vector();
- try
- {
- RecordEnumeration re=rs.enumerateRecords(null, null, false);
- while(re.hasNextElement())
- {
- v.addElement(new String(re.nextRecord()));
- }
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- return v;
- }
- //关闭记录集
- public void closeRecordStore()
- {
- try
- {
- rs.closeRecordStore();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- }