Java tutorial
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /** * Reads and discards all characters from the input stream until a \r\n or EOF is encountered * @param in * @return */ public static int discardUntilNewLine(InputStream in) { int ch; int num = 0; while (true) { try { ch = in.read(); if (ch == -1) break; num++; if (ch == '\n') break; } catch (IOException e) { break; } } return num; } }