rmsutil.java

来自「PDA餐饮管理系统,在掌上电脑实现的,可以开台,点菜等多功能模块」· Java 代码 · 共 115 行

JAVA
115
字号
package rms;

import javax.microedition.rms.*;

/**
 * rms访问公用类
 * @author hong
 *
 */
public class RMSUtil {

	public static RecordStore openRSAnymay(String rsname) {
		RecordStore rs = null;

		if (rsname.length() > 32)
			return null;

		try {
			rs = RecordStore.openRecordStore(rsname, true);
			return rs;
		} catch (Exception e) {
			return null;
		}
	}

	public static RecordStore openRSExisted(String rsname) {
		RecordStore rs = null;

		if (rsname.length() > 32)
			return null;

		try {
			rs = RecordStore.openRecordStore(rsname, false);
			return rs;
		} catch (Exception e) {
			return null;
		}
	}

	public static boolean deleteRS(String rsname) {
		if (rsname.length() > 32)
			return false;

		try {
			RecordStore.deleteRecordStore(rsname);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

    public static int writeCharToRS(RecordStore rs,char data){
		byte[] tmp=new byte[2];
		tmp[0]=(byte)(0xff&(data>>8));
		tmp[1]=(byte)(0xff&(data>>0));
		
		try
		{
			return rs.addRecord(tmp,0,tmp.length);
		}
		catch (Exception e)
		{
		}
		return -1;
	}
    
    public static char readCharFromRS(RecordStore rs,int recordid){
    	byte[] tmp=new byte[2];
    	try
    	{
    		tmp=rs.getRecord(recordid);
    	}
    	catch(Exception e)
    	{
    		
    	}
    	char result=(char)(tmp[0]&0x00ff);
    	result=(char)((result<<8)+(char)(tmp[1]&0x00ff));
    	return result;
    }
    
    public static int writeIntToRS(RecordStore rs,int data){
		byte[] tmp=new byte[4];
		tmp[0]=(byte)(0xff&(data>>24));
		tmp[1]=(byte)(0xff&(data>>16));
		tmp[2]=(byte)(0xff&(data>>8));
		tmp[3]=(byte)(0xff&(data>>0));
		
		try
		{
			return rs.addRecord(tmp,0,tmp.length);
		}
		catch (Exception e)
		{
		}
		return -1;
	}
    
    public static int readIntFromRS(RecordStore rs,int recordid){
    	byte[] tmp=new byte[4];
    	try
    	{
    		tmp=rs.getRecord(recordid);
    	}
    	catch(Exception e)
    	{
    		
    	}
    	int result=(tmp[0]&0x0000ff);
    	result=(result<<8)+(tmp[1]&0x000000ff);
    	result=(result<<8)+(tmp[2]&0x000000ff);
    	result=(result<<8)+(tmp[3]&0x000000ff);
    	return result;
    }}

⌨️ 快捷键说明

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