newbie to Java IO tech

Hallo,

How do i convert a integer to a byte and add them to a bytearray  and then write to a outputstream.

similarly how do i convert a string to a byte  and add to a bytearray and then write to  a outputstream.

String s = "hallo";
byte[] a = String.getBytes(s);

i know this method but after converting to a byte array a
i need to add this to another byte array
how could i do it

finally combining integer and string  converted to a byte and adding them to a bytearray and later write to a outputstream

With regards,

Ashok.G
LVL 5
ashok3sepAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

petmagdyCommented:
String value = String.valueOf(urInteger);
like:
String value = String.valueOf(12);

or like
int nVal = 15;
String statment = "The value is: " + String.valueOf(nVal);
byte[] bArray = statment.getBytes();
System.out.printlln(bArray0;
0
gnoonCommented:
You can use java.io.DataOutputStream class for writing primative types (int, long, float, double, boolean etc.) to an outputstream.

DataOutputStream dataoutputstream = new DataoutputStream(outputstream);
dataoutputstream.write(1);
dataoutputstream.writeBoolean(true);
dataoutputstream.writeBytes("hello");
dataoutputstream.close();
0
gnoonCommented:
writing:

DataOutputStream dataoutputstream = new DataOutputStream(outputstream);
dataoutputstream.writeInt(1);
dataoutputstream.writeBoolean(true);
dataoutputstream.writeUTF("hello");
dataoutputstream.close();

reading:

DataInputStream datainputstream = new DataInputStream(inputstream);
int iV = datainputstream.readInt();
boolean bV = datainputstream.readBoolean();
String sV = datainputstream.readUTF();
datainputstream.close();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
>> i need to add this to another byte array

Add to another byte-array? Do you mean you want to add these values with the values in another byte[] or do you want to append to another byte[] ?
0
CEHJCommented:
>>adding them to a bytearray and later write to a outputstream

You may be OK simply writing the first array to the stream, followed by the second one
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.