LineNumberReader LineNumberReader(Reader, int) in Java

LineNumberReader(Reader, int): This method is available in the java.io.LineNumberReader class of Java.

Syntax:

java.io.LineNumberReader.LineNumberReader(Reader in, int sz)

This method takes two arguments. This method creates a new line-numbering reader, reading characters into a buffer of the given size.

Parameters: Two parameters are required for this method.

in: A Reader object to provide the underlying stream.

sz: An int specifying the size of the buffer

Exceptions: NA

Approach

Java

import java.io.LineNumberReader;
import java.io.Reader;
import java.io.StringReader;

public class LineNumberReaderLineNumberReader2 {
    public static void main(String[] args) {

        Reader in = new StringReader("Hello");
        int sz = 10;
        LineNumberReader lineNumberReader =
new LineNumberReader(in, sz);

        System.out.println(lineNumberReader);
    }
}

Output:

java.io.LineNumberReader@7637f22


Some other methods of LineNumberReader

getLineNumber()This method gets the current line number.

LineNumberReader(Reader)This method creates a new line-numbering reader, using the default input buffer size.

mark(int)This method marks the present position in the stream.

read()This method read a single character.

read(char[], int, int)This method read characters into a portion of an array.

readLine()This method read a line of text.

reset()This method resets the stream to the most recent mark.

setLineNumber(int)This method sets the current line number.

skip(long)This method skips characters.

No comments:

Post a Comment