Here you can find the source of readLine(Reader ir)
public static String readLine(Reader ir) throws IOException
//package com.java2s; //The contents of this file are subject to the "Simplified BSD License" (the "License"); import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.Reader; public class Main { public static String readLine(InputStream is, String encoding) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); int c;//from w ww.j ava2 s . com boolean bAny = false; while ((c = is.read()) > 0 && c != '\n') { bAny = true; if (c != '\r') bos.write(c); } if (c == -1 && !bAny) return null; bos.close(); return bos.toString(encoding); } public static String readLine(Reader ir) throws IOException { StringBuffer sb = new StringBuffer(); int c; boolean bAny = false; while ((c = ir.read()) > 0 && c != '\n') { bAny = true; if (c != '\r') sb.append((char) c); } if (c == -1 && !bAny) return null; return sb.toString(); } }