如果你用LineNumberReader的read 或 readLine()方法 每一次读取lineNumber都会+1了,
- public int read(char cbuf[], int off, int len) throws IOException {
- synchronized (lock) {
- int n = super.read(cbuf, off, len);
- for (int i = off; i < off + n; i++) {
- int c = cbuf[i];
- if (skipLF) {
- skipLF = false;
- if (c == '\n')
- continue;
- }
- switch (c) {
- case '\r':
- skipLF = true;
- case '\n': /* Fall through */
- lineNumber++;
- break;
- }
- }
- return n;
- }
- }
- public String readLine() throws IOException {
- synchronized (lock) {
- String l = super.readLine(skipLF);
- skipLF = false;
- if (l != null)
- lineNumber++;
- return l;
- }
- }
复制代码 |