I am using the following code to establish a HTTP connection and read data:
con = (HttpURLConnection) new URL("http://stream.twitter.com/1/statuses/sample.json").openConnection();
...
con.connect();
while (line = rd.readLine()) {
if (line.contains("\r\n")) {
System.out.println("Carriage return + new line");
}
}
However, it seems like “\r\n” is not part of the string (line), although the server does return them. How can I read the data and detect “\r\n”?
Thanks,
Joel
If
rdis of typeBufferedReaderthere is no way to figure out ifreadLine()returned something that ended with\n,\ror\r\n… the end-of-line characters are discarded and not part of the returned string.If you really care about these characters, you can’t go through
readLine(). You’ll have to for instance read the characters one by one throughread().