I have been reading the Java Tutorials on I/O in an attempt to understand stream and their proper usage. Say I have two devices that are connected, and an InputStream and OutputStream on both devices. How do I transfer data between the two?
For example, if I wanted to one device to send a bunch of words to the other device, which would then print them to the screen. How would that work?
public class Device1 {
// assuming connectedDevice is something
String[] words = new String()[]{"foo", "bar", "baz"};
OutputStream os = connectedDevice.getOutputStream();
InputStream is = connectedDevice.getInputStream();
/*
How to write to output stream?
*/
}
public class Device2 {
// assuming connectedDevice is something
ArrayList<String> words = new ArrayList<String>();
OutputStream os = connectedDevice.getOutputStream();
InputStream is = connectedDevice.getInputStream();
/*
How can I somehow get the words using `read()` and `put()`
them into the ArrayList for use?
*/
}
Maybe I'm doing all of this wrong. Thanks in advance for any help in understanding.
ArrayList.