Here you can find the source of readLine(InputStream in)
public static String readLine(InputStream in) throws IOException
//package com.java2s; import java.io.*; public class Main { /**/*from w w w . j a va2 s . c o m*/ * Reads from the input stream until a linefeed is encountered. All data up until that point is returned as a * string. If the byte preceding the linefeed is a carriage return, that is also removed from the returned value. * The stream is positioned immediately after the linefeed. */ public static String readLine(InputStream in) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int c = in.read(); if (c == -1 || c == '\n') return ""; int c2 = in.read(); while (c2 != -1 && (char) c2 != '\n') { baos.write(c); c = c2; c2 = in.read(); } if ((char) c != '\r') baos.write(c); return new String(baos.toByteArray(), "UTF-8"); } }