Java I/O problem

this is my program that i had written.
outstream = tcpipSocket.getOutputStream();
instream  = tcpipSocket.getInputStream();

//Identify Command Sequence.
int protocol_version = 513;
int check_sum = 543;
String protocol_name = "PRS";
byte[] identify = {10,20,(byte)protocol_version,0,(byte)check_sum};

BufferedOutputStream bufferoutput1 = new BufferedOutputStream(outstream);


length = instream.available();
BufferedInputStream bufferinput1 = new BufferedInputStream(instream);

for (int i=1; i<=length; i++)
      byte response = (byte);

I dont want to have a byte array  to add all the codes in side the byte array.

Instead it should be possible for me to add strings, integers, and bytes to the output stream.

how could i do it.
please help me out to reach the solution

With regards,
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.

use DataOutputStream.
Hi D4Ly,

You can use the BufferedWriter instead

Use ObjectInputStream and ObjectOutputStream to send the objects you want. You will need to pass to the ObjectInput/OutputStream constructors the input/output stream of the socket. For more info:
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.


if u have String for example u can simply:
String strVal = "hello i will become a byte array now";
byte[] byteValue = strVal.getBytes();

for int u can do this
byte[] byteValue = String.valueOf(12).getBytes();
Go to the section where it says "Transporting Objects over Sockets"
Thsi is the part you are interested in:

ObjectInputStream ois = new ObjectInputStream(tcpipSocket.getInputStream());
ObjectOutputStream oos = new ObjectOutputStream(tcpipSocket.getOutputStream());

Then to send objects simply do:

oos.writeObject(new Date());

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
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

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.