Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.io.Reader;

public class Main {
    public static String readLineLimit(Reader reader, int limit) throws IOException {
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < limit; i++) {
            int c = reader.read(); //Read in single character
            if (c == -1) {
                return ((sb.length() > 0) ? sb.toString() : null);
            }

            if (((char) c == '\n') || ((char) c == '\r')) { //Found end of line, break loop.
                break;
            }

            sb.append((char) c); // String is not over and end line not found
        }

        return sb.toString(); //end of line was found.
    }
}