I´ve got a DataInputStream and I have a method, which should return a String. I know, that my Datastream receives a packet, containing a String. But my code, which I´ve written doesn´t compile. I´m using TCP- sockets and streams to send / receive data. It is important to say, that I must use Java 1.8 compiler! Thats the reason, why I cant use in.readAllBytes()
public String readString(DataInputStream in) throws IOException {
String str;
byte[] bytes = in. //dont know what to write here
str = bytes.toString();
return str;
}
So, as you can see I first create a new ByteArray variable. After this, the byteArray should convert to a String.