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

📄 apppreferences.java

📁 一个基于J2ME技术的程序,使你可以远程控制装有服务端的PC.
💻 JAVA
字号:
/* * JRemCntl - Copyright (C) 2007 Filippo Di Vattimo <fildiv@gmail.com> * See COPYING */package fildiv.jremcntl.client.core;import java.util.Enumeration;import java.util.Hashtable;import javax.microedition.rms.RecordEnumeration;import javax.microedition.rms.RecordStore;import javax.microedition.rms.RecordStoreException;class AppPreferences {	private String mRecordStoreName;	private Hashtable mHashtable;	public AppPreferences(String recordStoreName) throws RecordStoreException {		mRecordStoreName = recordStoreName;		mHashtable = new Hashtable();		load();	}	public String get(String key) {		return (String) mHashtable.get(key);	}	public void put(String key, String value) {		if (value == null)			value = "";		mHashtable.put(key, value);	}	private void load() throws RecordStoreException {		RecordStore rs = null;		RecordEnumeration re = null;		try {			rs = RecordStore.openRecordStore(mRecordStoreName, true);			re = rs.enumerateRecords(null, null, false);			while (re.hasNextElement()) {				byte[] raw = re.nextRecord();				String pref = new String(raw);				// Parse out the name.				int index = pref.indexOf('|');				String name = pref.substring(0, index);				String value = pref.substring(index + 1);				put(name, value);			}		} finally {			if (re != null)				re.destroy();			if (rs != null)				rs.closeRecordStore();		}	}	public void save() throws RecordStoreException {		RecordStore rs = null;		RecordEnumeration re = null;		try {			rs = RecordStore.openRecordStore(mRecordStoreName, true);			re = rs.enumerateRecords(null, null, false);			// First remove all records, a little clumsy.			while (re.hasNextElement()) {				int id = re.nextRecordId();				rs.deleteRecord(id);			}			// Now save the preferences records.			Enumeration keys = mHashtable.keys();			while (keys.hasMoreElements()) {				String key = (String) keys.nextElement();				String value = get(key);				String pref = key + "|" + value;				byte[] raw = pref.getBytes();				rs.addRecord(raw, 0, raw.length);			}		} finally {			if (re != null)				re.destroy();			if (rs != null)				rs.closeRecordStore();		}	}}

⌨️ 快捷键说明

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