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 120323
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 array
of bytes.
ie. I'd like to be able to do...
|
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 data be intact, or do Strings have problems with...
|
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 into "usable"
data. For example, the first 4 bytes...
|
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 delimiters
for the message.
when we use...
|
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
to convert the picture into base64Array format in...
|
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 double post in this newsgroup, I cannot set my...
|
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
string.
I have packets coming in from 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
getting scrambled in the conversion. In short,...
|
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 covert
this. I am new to the .NET world and still...
|
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 anyone that knows how to get this into a .net...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |