2010-04-21 58 views
0

我在readUTF中获取了以下代码的超时值。任何想法为什么?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(); 
+0

我需要的是DataInputStream的字符串表示形式 – 2010-04-21 14:16:04

回答

1

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

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

谢谢。这正是我需要稍作修改转换为字符串。 is = hc.openInputStream(); String list = new String(IOUtilities.streamToBytes(is)); – 2010-04-22 18:13:42

+0

ah right - streamToBytes返回一个字节[] - 我更新了我的答案中的代码以反映这一点,谢谢 – 2010-04-22 21:34:12