Hi,
I am trying to convert a byte array to a string. I am using the
possible ways
but not getting the result.
DatagramPacket dgram = new DatagramPacket(buf, buf.length);
ByteArrayInputStream byteIn = new ByteArrayInputStream (dgram.getData
(), 0, dgram.getLength ());
ObjectInputStream oin = new ObjectInputStream(byteIn);
Object obj = oin.readObject();
String recvString = obj.toString();
DataInputStream dataIn = new DataInputStream (byteIn);
String recvString = dataIn.readLine();
String recvString = new String(dgram.getData(),0,dgram.getLength());
String recvString = dataIn.readLine();
I am trying all these to convert my byte array to a string
But I am getting exception as invalid header.
Can anybody please suggest me.
Regards,
Hari. 2 120208
Did I understand this completely wrong, or can't you just use the
String(byte [] bytes) constructor? ha******@yahoo.com (Hari Prasad) wrote in message news:<25**************************@posting.google. com>... Hi, I am trying to convert a byte array to a string. I am using the possible ways but not getting the result.
DatagramPacket dgram = new DatagramPacket(buf, buf.length); ByteArrayInputStream byteIn = new ByteArrayInputStream (dgram.getData (), 0, dgram.getLength ());
ObjectInputStream oin = new ObjectInputStream(byteIn); Object obj = oin.readObject(); String recvString = obj.toString(); DataInputStream dataIn = new DataInputStream (byteIn); String recvString = dataIn.readLine();
String recvString = new String(dgram.getData(),0,dgram.getLength()); String recvString = dataIn.readLine();
I am trying all these to convert my byte array to a string But I am getting exception as invalid header.
Can anybody please suggest me.
Regards, Hari. so*****@gmail.com (Somaiah Kumbera) wrote in message news:<d6**************************@posting.google. com>... Did I understand this completely wrong, or can't you just use the String(byte [] bytes) constructor?
"just" is the critical word. If you use String(byte [] bytes), the default
encoding will be chosen, which is dependant on you locale.
You should use String(byte [] bytes,String encoding) instead; this makes
the used encoding explicit and reproducable on different machines.
example: new String(ba,"utf-8")
This assumes your data is utf-8 encoded.
google the web for "java encoding" encoding to see which encodings are
avaible. ha******@yahoo.com (Hari Prasad) wrote in message news:<25**************************@posting.google. com>... Hi, I am trying to convert a byte array to a string. I am using the possible ways but not getting the result.
DatagramPacket dgram = new DatagramPacket(buf, buf.length); ByteArrayInputStream byteIn = new ByteArrayInputStream (dgram.getData (), 0, dgram.getLength ());
ObjectInputStream oin = new ObjectInputStream(byteIn); Object obj = oin.readObject(); String recvString = obj.toString(); DataInputStream dataIn = new DataInputStream (byteIn); String recvString = dataIn.readLine();
String recvString = new String(dgram.getData(),0,dgram.getLength()); String recvString = dataIn.readLine();
I am trying all these to convert my byte array to a string But I am getting exception as invalid header.
Can anybody please suggest me.
Regards, Hari. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: matt melton |
last post by:
Hi there,
I am trying to write a method that accepts an array of any primitive
type and will return the same array without copying memory as an...
|
by: Hal Vaughan |
last post by:
If I have a byte and I convert it to string (String sData = new
String(byte bData), then convert it back (byte bData = sData.getBytes()),
will all...
|
by: Pete Davis |
last post by:
I've never done this in C# so I don't know what the appropriate way of doing
it is.
I've got an array of bytes and I need to convert the array...
|
by: Prabhu |
last post by:
Hi,
We are having problem in converting a byte array to string, The byte array
has char(174), char(175), char(240), char(242) and char(247) as...
|
by: iyuen |
last post by:
I'm having problems with converting a byte array to an image object~
My byte array is an picture in VB6 StdPicture format. I've used propertybag...
|
by: Benoit |
last post by:
Hi, what is the most performing way to convert a byte stream to a string?
Byte() to be converted to String.
Thanks, iBen.
Sorry if it ia a...
|
by: David |
last post by:
I note that you can null teminate a string by adding controlchar.null.
Is there a way of adding a null to a Buffer of Bytes and converting it to a...
|
by: moondaddy |
last post by:
I need to convert a byte array to a string and pass it as a parameter in a
URL and then convert it back to the original byte array. However, its...
|
by: manmit.walia |
last post by:
Hello All,
I have tried multiple online tools to convert an VB6 (bas) file to
VB.NET file and no luck. I was hoping that someone could help me...
|
by: ogtheterror |
last post by:
Hi I have a very limited understanding of Python and have given this the best shot i have but still have not been able to get it working.
Is there...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
| |