[英]why readLine() works, and readUTF() always throws IOException
I send a post request to an address, and this address will return a xml format data back. 我将发帖请求发送到一个地址,该地址将返回xml格式的数据。
I can print out the data by readLine(),
but when i use readUTF(),
it always throws IOException
. 我可以通过readLine(),
打印出数据readLine(),
但是当我使用readUTF(),
它总是抛出IOException
。 below is the code 下面是代码
DataInputStream input = new DataInputStream(urlCon.getInputStream());
String inputLine = "";
if((inputLine = input.readUTF()) != null) {
System.out.println(inputLine.toString());
}
input.close();
why readUTF() does not work? 为什么readUTF()不起作用? is it because the data is xml format? 是因为数据是xml格式?
If you're reading lines, use readLine()
. 如果要读取行,请使用readLine()
。 Data to be read with readUTF()
must have been written with writeUTF().
用readUTF()
读取的数据必须已经用writeUTF().
写入writeUTF().
See the Javadoc. 请参阅Javadoc。
NB readUTF()
doesn't return null, so testing for it is futile. 注意readUTF()
不返回null,因此对其进行测试是徒劳的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.