Java LineNumberReader.read(char[] cbuf, int off, int len)
Syntax
LineNumberReader.read(char[] cbuf, int off, int len) has the following syntax.
public int read(char[] cbuf, int off, int len) throws IOException
Example
In the following code shows how to use LineNumberReader.read(char[] cbuf, int off, int len) method.
//from w w w. j ava 2 s. co m
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
public class Main {
public static void main(String[] args) throws IOException {
char[] cbuf = new char[5];
// create new reader
FileReader fr = new FileReader("C:/test.txt");
LineNumberReader lnr = new LineNumberReader(fr);
// read characters into the buffer
int i = lnr.read(cbuf, 2, 3);
System.out.println("Number of char read: " + i);
// for each character in the buffer
for (char c : cbuf) {
// if char is empty
if ((int) c == 0)
c = '-';
// prints char
System.out.print(c);
}
lnr.close();
}
}
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »