How do I send an EOF for a Java InputStream element?
•
Java
So I have the following code to open the input stream and successfully collect information:
httpInput = httpconnection.openInputStream(); sb= new StringBuffer(); while (ch != -1) { ch = httpInput.read(); sb.append((char)ch); }
However, when I try to use the same string (sb. Tostring()) in another method, I receive an error saying "expect the end of the file." So how do I append EOF characters to my string? Note: the response is basically an XML document from a remote server
So when the code reaches the "parse" line, it will give the above error:
bis = new ByteArrayInputStream(sb.toString(). getBytes()); doc = docBuilder. parse(bis);
I'm writing a BlackBerry app
AC
Solution
If you only want to read the stream into a byte array, try ioutilities streamToBytes()
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码