BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 12-21-2006, 04:37 PM   #1
newToThis
Knows Where the Search Button Is
 
Join Date: Nov 2006
Model: 7250
Carrier: Carrier Has Arrived
Posts: 29
Default convert byte[] array into a string

Please Login to Remove!

hi im reading a record that stored a string object
as a byte array

how can i convert from byte array to string..
i tried to do this strategy..

byte[] data = current.getRecord(recordId);

Code:
  try
  {
    vfm.add(new LabelField(new String(data, "US-ASCII")));
  }
  catch(java.io.UnsupportedEncodingException ex)
  {
  
  }
i dont know the reason why it's not showing anything.
Offline  
Old 12-22-2006, 05:52 PM   #2
newToThis
Knows Where the Search Button Is
 
Join Date: Nov 2006
Model: 7250
Carrier: Carrier Has Arrived
Posts: 29
Default (y) found the problem

nevermind.. i traced the problem to the
approach i was using in storing the bytes.

i used bytearrayoutputstream when a simple
StringObject.getBytes() was enuf to get the byte array.
and convert back to String x = new String(byte[] array);
Offline  
Old 12-22-2006, 08:28 PM   #3
ecarmody
Thumbs Must Hurt
 
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 9800
Carrier: AT&T
Posts: 82
Default

Here is the approach I use to read the recordstore and convert to string. Actually, I convert to fields in a structure, but this example shows just a string.

Code:
byte [] data = rs.getRecord(id);
bin = new ByteArrayInputStream(data);
din = new DataInputStream(bin);
String stringData = din.readUTF();
Offline  
Old 12-27-2006, 06:23 PM   #4
newToThis
Knows Where the Search Button Is
 
Join Date: Nov 2006
Model: 7250
Carrier: Carrier Has Arrived
Posts: 29
Default

thank you for the reply ecarmody i will give this
a try. i was wondering how the bytearraystream
can be used to make this work.
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Lot of OEM APPLE iPAD LCD And White Front Glass Replacement 6091l-1402C picture

Lot of OEM APPLE iPAD LCD And White Front Glass Replacement 6091l-1402C

$17.99



Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013 picture

Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013

$40.90



OEM Battery for MacBook Pro 17

OEM Battery for MacBook Pro 17" A1309 A1297 Early 2009 Mid 2009 2010 MC226

$40.90



A1618 NEW OEM Battery for MacBook Pro 15

A1618 NEW OEM Battery for MacBook Pro 15" Retina A1398 Mid 2015 020-00079

$43.90



NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch picture

NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch

$31.90



NEW OEM A1618 Battery for Apple MacBook Pro 15” Retina 99.5Wh A1398 Mid 2015 picture

NEW OEM A1618 Battery for Apple MacBook Pro 15” Retina 99.5Wh A1398 Mid 2015

$43.90







Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.