Java BufferedReader Read Line readLine(BufferedReader reader)

Here you can find the source of readLine(BufferedReader reader)

Description

read Line

License

Apache License

Declaration

public static String readLine(BufferedReader reader) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;

import java.io.IOException;

public class Main {
    public static String readLine(BufferedReader reader) throws IOException {
        int ch = -1;
        StringBuffer line = new StringBuffer();

        ch = reader.read();/*from   ww w .ja  v a2s.c o  m*/
        while ((ch != -1) && (ch != 13) && (ch != 10)) {
            line.append((char) ch);
            ch = reader.read();
        }

        if ((ch == -1) && (line.length() == 0)) {
            return null;
        }

        switch ((char) ch) {
        case '\r':
            reader.mark(2);
            switch (ch = reader.read()) {
            case 13:
                if ((char) (ch = reader.read()) == '\n')
                    break;
                reader.reset();
                break;
            case 10:
                break;
            case -1:
                break;
            default:
                reader.reset();
            }
            break;
        case '\n':
        }

        return line.toString();
    }
}

Related

  1. readLine(BufferedReader br, int maxlen)
  2. readLine(BufferedReader in)
  3. readLine(BufferedReader in)
  4. readline(BufferedReader in, BufferedReader err)
  5. readLine(BufferedReader input)
  6. readLine(BufferedReader reader)
  7. readLine(BufferedReader reader)
  8. readLine(BufferedReader reader, StringWriter writer)
  9. readLine(File f)