A simple programm
DataInputStream in = new DataInputStream(System.in);
while(true)
System.out.println(in.readUTF());
Behaves somewhat weird: it refuses to output the inputed text… I use terminal to input some text into it, but there’s nothing in the output. What’s wrong with it?
It’s not weird at all.
readUTFexpects a very specific length-prefixed format as written byDataOutputStream. That’s not what your terminal will be providing. See the documentation inDataInput.readUTFfor more details.You should generally just use a
Scanneror create anInputStreamReaderaroundSystem.in, and aBufferedReaderaround that, and useBufferedReader.readLine().