Announcement

Collapse
No announcement yet.

[Hỏi][J2ME] Về việc lưu trữ và load dữ liệu theo cơ chế RMS?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Hỏi][J2ME] Về việc lưu trữ và load dữ liệu theo cơ chế RMS?

    Hiện tại minh có làm 1 phần của đồ án. Trong đó có sử dụng cơ chế lưu dữ liệu RMS. Mình lưu được dữ liệu theo tiếng Việt (có dấu). Khi ghi xong và load dữ liệu vào mảng thì in dữ liệu ra bằng cách:
    System.out.println(str[1]);
    Lúc này dữ liệu bị lỗi font. Nhưng chép file jar vào máy điện thoại di động chạy ứng dụng thì tiếng Việt vẫn hiển thị tốt.
    Qua thêm 1 vài hàm so sánh thì lúc này thực sự nảy sinh vấn đề:
    - Hàm tìm chuỗi tồn tại trong một chuỗi sử dụng dữ liệu do RMS load ra mảng thì hoàn toàn sai giá trị.
    - Hàm tìm chuỗi tồn tại trong một chuỗi sử dụng dữ liệu tạm (mảng tạm) thì hoàn toàn đúng.
    Đã test thử 2 ứng dụng trên ĐTDĐ. Không biết RMS có hỗ trợ lưu tiếng Việt không nhỉ?
    Bạn nào có chút kinh nghiệm về vấn đề này mong chỉ giáo giùm mình!
    Thân!
    --Code:
    Code:
    public void openRecStore()
        {
            try
            {
                rs_tuyen=RecordStore.openRecordStore ( REC_STORE, true );
                rs_luotdi=RecordStore.openRecordStore ( REC_STORE2, true);
                rs_luotve=RecordStore.openRecordStore ( REC_STORE3, true);
                
            }
            catch(Exception e)
            {
                db(e.toString ());
            }
        }
        public void closeRecStore()
        {
            try
            {
                 rs_tuyen.closeRecordStore ();
                 rs_luotdi.closeRecordStore ();
                 rs_luotve.closeRecordStore ();
            }
            catch(Exception e)
            {
                db(e.toString ());
            }
            
        }
        public void deleteRecStore()
        {
            if(RecordStore.listRecordStores ()!=null)
            {
                try
                {
                    RecordStore.deleteRecordStore ( REC_STORE );
                    RecordStore.deleteRecordStore ( REC_STORE2 );
                    RecordStore.deleteRecordStore ( REC_STORE3 );
                    
                }
                catch(Exception e)
                {
                    db(e.toString ());
                }
            }
        }
    public void writeStream(String[] sData, RecordStore rs1)
        {
            try
            {
               
                byte[] record;
                for (int i=0; i<sData.length;i++)
                {
                    record=sData[i].getBytes ();
                    rs1.addRecord(record,0,record.length);
                    
                }
               
            }
            catch(Exception e)
            {
                db(e.toString ());
            }
        }
        public void readStream( )
        {
            try
            {
                byte[] recData= new byte[50];
                int len;
               
                
                for(int i=1; i<=rs_tuyen.getNumRecords ();i++)
                {
                    if(rs_tuyen.getRecordSize ( i)>recData.length )
                    {
                        recData =new byte[rs_tuyen.getRecordSize ( i) ];
                    }
                    len=rs_tuyen.getRecord ( i, recData, 0);
                    rs_tuyen.getRecord ( i, recData, 0);
                    b1[i]= new String(recData,0,len);
                    //System.out.println(b1[i]);
                    
                    
                    
                }
                for(int i=1; i<=rs_luotdi.getNumRecords ();i++)
                {
                    if(rs_luotdi.getRecordSize ( i)>recData.length )
                    {
                        recData =new byte[rs_luotdi.getRecordSize ( i) ];
                    }
                    len=rs_luotdi.getRecord ( i, recData, 0);
                    rs_luotdi.getRecord ( i, recData, 0);
                    c1[i]= new String(recData,0,len);
                    //System.out.println(c1[i]);
                    
                    
                    
                }
                for(int i=1; i<=rs_luotve.getNumRecords ();i++)
                {
                    if(rs_luotve.getRecordSize ( i)>recData.length )
                    {
                        recData =new byte[rs_luotve.getRecordSize ( i) ];
                    }
                    len=rs_luotve.getRecord ( i, recData, 0);
                    rs_luotve.getRecord ( i, recData, 0);
                    d1[i]= new String(recData,0,len);
                    //System.out.println(d1[i]);
                    
                    
                    
                }
                
                
                
            }
            catch(Exception e)
            {
                db(e.toString ());
            }
           
        }
    -------------------------------------
    Đời là bể khổ.
    Quay đầu là bờ ai ngờ là đại dương.
    ------------------------------------------------------------------------

  • #2
    Đã tìm được hướng giải quyết! Chân thành cảm ơn các bạn đã quan tâm đọc bài.
    -------------------------------------
    Đời là bể khổ.
    Quay đầu là bờ ai ngờ là đại dương.
    ------------------------------------------------------------------------

    Comment

    LHQC

    Collapse
    Working...
    X