J2ME学习之简单RMS

 

 import javax.microedition.lcdui.*;
 import javax.microedition.rms.*;
 import java.io.*;


 public class Rms extends Canvas //implements Runnable
        {
        public static String name ="afly";
        private RecordStore rs=null;
        private boolean empty=true;
        public Rms ()
        {
        //new Thread(this).start();
           xieru();
          
        }
        public void xieru(){
         try{
           rs=RecordStore.openRecordStore(name,true);
           if(rs.getNumRecords()>0){
               empty=false;
            }else{
              doa();                                 
                                 }
           }catch(RecordStoreException e){}
                         }
       public void doa(){
           try {
                init("bb.txt");
                init("aa.png");
              }catch(IOException e){
              }catch(RecordStoreException ex){}
                      }     
             
      private void init(String str) throws IOException,RecordStoreException{
          InputStream is=this.getClass().getResourceAsStream("/"+str);
           if(is!=null){
             ByteArrayOutputStream baos= new ByteArrayOutputStream();
             byte[] data=new byte[1024];
             int ch=0;
             while((ch=is.read(data,0,data.length))!=-1){
                  baos.write(data,0,ch);                }
             byte[] a=baos.toByteArray();
             rs.addRecord(a,0,a.length);
             is.close();
             baos.close();
                    }                                    }
            
            
                 
                                               
        protected void paint(Graphics g){
         g.setColor(0x00ffffff);
         g.fillRect(0,0,getWidth(),getHeight());
         g.setColor(0x00000000);
         String aa=null;
         try{
           byte[] text=rs.getRecord(1);
           aa=new String(text,"UTF-8");
           }catch(RecordStoreException e){}catch(IOException ex){}
         g.drawString(aa,0,0,0); 
          Image bb=null;
          
         try{
           byte[] img=rs.getRecord(2);
           bb = Image.createImage(img,0,img.length);
          }catch(RecordStoreException e){}
         
          g.drawImage(bb,0,20,0);
         
         
                                       }

 
       }                                
          

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值