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 rd is of type BufferedReader there is no way to figure out if readLine() returned something that ended with \n, \r or \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 through read().