user1673627
user1673627

Reputation: 271

Java InputStream Malfunction

When I run the following code segment in debug mode, as soon as I execute the line str=in.readUTF(), program stops.

InputStream sin=socket.getInputStream();
DataInputStream in=new DataInputStream(sin);

String str="";
str=in.readUTF();

System.out.println("This line is not reached");

I use netbeans. Although no exception is shown, the program stops. While in debugging mode, initially, the str=in.readUTF() line is green but when I press F7 or F8 to continues, the green line turns pink and program stops.

Upvotes: 0

Views: 94

Answers (2)

user207421
user207421

Reputation: 310893

Unless you wrote the data with DataOutputStream.writeUTF() you can't read it with DataInputStream.readUTF(). Possibly you should be using readLine(). It depends entirely on how you wrote the data, which you haven't told us.

Upvotes: 0

Matteo
Matteo

Reputation: 14930

As documented at http://docs.oracle.com/javase/1.4.2/docs/api/java/io/DataInput.html#readUTF() the calls reads a string from the stream and returns it.

Your debugger is just waiting for input.

Upvotes: 1

Related Questions