Here you can find the source of readLine(InputStream input)
Parameter | Description |
---|---|
input | - the input string to read from |
Parameter | Description |
---|---|
IOException | an exception |
null
if end of input is reached
public static String readLine(InputStream input) throws IOException
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { /**/*from ww w .jav a2 s .c om*/ * read a line terminated by a new line '\n' character * @param input - the input string to read from * @return the line read or <code>null</code> if end of input is reached * @throws IOException */ public static String readLine(InputStream input) throws IOException { return readLine(input, '\n'); } /** * read a line from the given input stream * @param input - the input stream * @param terminatorChar - the character used to terminate lines * @return the line read or <code>null</code> if end of input is reached * @throws IOException */ public static String readLine(InputStream input, char terminatorChar) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); while (true) { int c = input.read(); if (c < 0 && bos.size() == 0) return null; if (c < 0 || c == terminatorChar) break; else bos.write(c); } return bos.size() > 0 ? bos.toString() : null; } }