J2ME road——J2ME实现RMS手机的存储
2010-04-02 17:32
204 查看
package src;
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.rms.*;
public class SimpleRMS extends MIDlet{
private RecordStore rs;
private static final String STORE_NAME = "My Record Store";
public SimpleRMS() throws Exception
{
rs = RecordStore.openRecordStore(STORE_NAME, true);
//Create some records in the store
String[] words = {"they", "mostly", "come", "at", "night" };
for(int i=0; i<words.length; i++)
{
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream dataOutputStream= new DataOutputStream(byteArrayOutputStream);
dataOutputStream.writeUTF(words[i]);
//add another dataOutputStream.writeXXX statements if you like
dataOutputStream.flush();
//add the record
byte[] recordOut =byteArrayOutputStream.toByteArray();
int newRecordId = rs.addRecord(recordOut, 0, recordOut.length);
System.out.println("Adding new record;"+ newRecordId + "value:" +recordOut);
dataOutputStream.close();
byteArrayOutputStream.close();
}
System.out.println("Record store now has" +rs.getNumRecords() +
"record(s) using" +rs.getSize() +"byte(s)"+
"[" +rs.getSizeAvailable() +"bytes free]");
//retrieve the records
for(int i =1;i<= rs.getNumRecords(); i++)
{
int recordSize = rs.getRecordSize(i);
if(recordSize >0)
{
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(rs.getRecord(i));
DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
String value = dataInputStream.readUTF();
System.out.println("Retrieved record;" + i+ "value:" +value);
dataInputStream.close();
byteArrayInputStream.close();
}
}
}
protected void destroyApp(boolean b) throws MIDletStateChangeException {
// TODO 自动生成方法存根
}
protected void pauseApp() {
// TODO 自动生成方法存根
}
protected void startApp() throws MIDletStateChangeException {
// TODO 自动生成方法存根
destroyApp(false);
notifyDestroyed();
}
}
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.rms.*;
public class SimpleRMS extends MIDlet{
private RecordStore rs;
private static final String STORE_NAME = "My Record Store";
public SimpleRMS() throws Exception
{
rs = RecordStore.openRecordStore(STORE_NAME, true);
//Create some records in the store
String[] words = {"they", "mostly", "come", "at", "night" };
for(int i=0; i<words.length; i++)
{
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream dataOutputStream= new DataOutputStream(byteArrayOutputStream);
dataOutputStream.writeUTF(words[i]);
//add another dataOutputStream.writeXXX statements if you like
dataOutputStream.flush();
//add the record
byte[] recordOut =byteArrayOutputStream.toByteArray();
int newRecordId = rs.addRecord(recordOut, 0, recordOut.length);
System.out.println("Adding new record;"+ newRecordId + "value:" +recordOut);
dataOutputStream.close();
byteArrayOutputStream.close();
}
System.out.println("Record store now has" +rs.getNumRecords() +
"record(s) using" +rs.getSize() +"byte(s)"+
"[" +rs.getSizeAvailable() +"bytes free]");
//retrieve the records
for(int i =1;i<= rs.getNumRecords(); i++)
{
int recordSize = rs.getRecordSize(i);
if(recordSize >0)
{
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(rs.getRecord(i));
DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
String value = dataInputStream.readUTF();
System.out.println("Retrieved record;" + i+ "value:" +value);
dataInputStream.close();
byteArrayInputStream.close();
}
}
}
protected void destroyApp(boolean b) throws MIDletStateChangeException {
// TODO 自动生成方法存根
}
protected void pauseApp() {
// TODO 自动生成方法存根
}
protected void startApp() throws MIDletStateChangeException {
// TODO 自动生成方法存根
destroyApp(false);
notifyDestroyed();
}
}
相关文章推荐
- j2me RMS无法实现持久化存储的问题
- 在J2ME中使用记录存储系统(RMS)存储信息
- Android编程实现手机自带内部存储路径的获取方法
- j2me实现手机通讯录的备份与还原
- J2ME开发中,用XML实现手机或PDA与PC通讯的思路
- J2ME中使用记录存储系统(RMS)存储信息
- j2me打包,FPS射击类游戏的实现-3G手机开发公开课-东方尚智,3g数字内容学院
- J2ME遍历手持机所有根路径找出并RMS存储可用空间最大路径
- [Unity3D]手机3D游戏开发:如何实现最高分的存储与显示(四)----使用PlayerPrefs存储数据到本地
- J2ME GUI实战之二 ----------LWUIT实现手机九宫图
- 分布式爬虫系统设计、实现与实战:爬取京东、苏宁易购全网手机商品数据+MySQL、HBase存储
- 利用J2ME和servlet技术实现手机发送邮件
- j2me写的手机程序无法实现的功能
- J2ME GUI实战之二 ----------LWUIT实现手机九宫图
- J2ME road——J2ME实现Lifecycle
- J2ME road——J2ME实现Canvas
- [Unity3D]手机3D游戏开发:如何实现最高分的存储与显示(一)----初始化显示的高分榜
- J2ME中使用记录存储系统(RMS)存储信息
- J2ME的RMS读写实现
- j2me实现手机拍照