Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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;
    }
}