Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array[ ][ ] Outputstream Question

Status
Not open for further replies.

ezl

Programmer
Aug 7, 2001
8
US
Hi...

I think this is pretty simple (hopefully!)...

I want to write a two dimensional array to an ouput stream (to sent the data to another machine). Elsewhere in my program I'm doing the same thing for text using the following code (note IPConnect is my own class...it just creates the socket):

IPconnect ipConnection=new IPconnect();
OutputStream out=ipConnection.connect( ipVar, portVar);
DataOutputStream dataOut=new DataOutputStream(out);
dataOut.writeUTF("Outgoing String");

How would I accomplish the same thing, but passing a two dimensional array instead of text?

Thanks in advance...

ezl
 
I want to save individual objects to an object output stream from one program, then read the objects back one by one, by the same program. How do I do this and how do I make the data persistent using a properties file or serialization?
 
Unless the objects are the same type and you can put them in a list or the receiving program knows exactly the number and type, this will be hard.

Similarly, if you persist them, whoever unpersists them needs to know WHAT was persisted. In any event, sending an object to an output stream is easy. Here is the example from the header of ObjectOutputStream:

FileOutputStream ostream = new FileOutputStream("t.tmp");
ObjectOutputStream p = new ObjectOutputStream(ostream);

p.writeInt(12345);
p.writeObject("Today");
p.writeObject(new Date());

p.flush();
ostream.close();
To read it in, you do the opposite.
 
Hi thanks for that. The objects are the same type. How would I do this?
 
If the objects are all of the same type, I'd put them in an array or List and send the array or List out the stream. Then the reader at the other end can read in the List or array and retrieve the individual objects. This would make things ALOT easier.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top