【问题标题】:readUTF timeout读取UTF超时
【发布时间】:2010-04-21 13:45:38
【问题描述】:

我在 readUTF 中使用以下代码超时。知道为什么吗?

hc = (HttpConnection) Connector.open("http://twitter.com/statuses/user_timeline/" + username + ".json");
int rc = hc.getResponseCode();

if (rc != HttpConnection.HTTP_OK) {
    throw new IOException("HTTP response code: " + rc);
}

DataInputStream dataInputStream = hc.openDataInputStream();
String list = dataInputStream.readUTF();

【问题讨论】:

  • 我需要的是 DataInputStream 的字符串表示

标签: java json blackberry twitter


【解决方案1】:

DataInputStream 仅用于从另一端由 Java 序列化的流中反序列化 Java 对象。我怀疑你真正想要的是:

InputStream is = hc.openInputStream();
String list = new String(IOUtilities.streamToBytes(is));

【讨论】:

  • 谢谢。这正是我需要稍作修改才能转换为字符串的内容。是 = hc.openInputStream(); String list = new String(IOUtilities.streamToBytes(is));
  • 啊,对 - streamToBytes 返回一个字节 [] - 我更新了答案中的代码以反映这一点,谢谢
猜你喜欢
  • 2020-01-19
  • 2014-08-06
  • 2019-08-20
  • 2014-06-06
  • 2011-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多