[java] Type conversions and arrays (and Datagrams!),
Members - Reputation: 122
Posted 10 April 2000 - 12:11 PM
Moderators - Reputation: 11404
Posted 10 April 2000 - 01:10 PM
String s = "Data";
byte data = new byte[s.length()];
s.getBytes(0, s.length(), data, 0);
For receiving non-string data you can use ByteArrayInputStream objects. Chain that to a DataInputStream, and you can use readInt(), readLong(), readChar(), etc. methods with it.
For outputing non-string data you can use ByteArrayOutputStream objects. Chain that to a DataOutputStream, and you can use writeInt(), writeLong(), writeChar(), etc. methods with it.