- java.lang.Object
 -  
      
- java.io.Reader
 -  
        
- java.io.BufferedReader
 -  
          
- java.io.LineNumberReader
 
 
 
 
-  
       
- 实现的所有接口
 -  
         
Closeable,AutoCloseable,Readable 
public class LineNumberReader extends BufferedReader
缓冲的字符输入流,用于跟踪行号。 该类定义了方法setLineNumber(int)和getLineNumber(),分别用于设置和获取当前行号。默认情况下,行号从0开始。此数字在读取数据时每line terminator递增一次,并且可以通过调用
setLineNumber(int)进行更改。 但请注意,setLineNumber(int)实际上并未更改流中的当前位置; 它只会更改getLineNumber()返回的getLineNumber()。通过换行符('\ n'),回车符('\ r')或回车符后面的任何一行,行被认为是terminated 。
- 从以下版本开始:
 - 1.1
 
 
-  
        
       
-  
             
构造方法摘要
构造方法 构造器 描述 LineNumberReader(Reader in)使用默认输入缓冲区大小创建新的行编号读取器。LineNumberReader(Reader in, int sz)创建一个新的行编号阅读器,将字符读入给定大小的缓冲区。 
-  
             
方法摘要
所有方法 实例方法 具体的方法 变量和类型 方法 描述 intgetLineNumber()获取当前行号。voidmark(int readAheadLimit)标记流中的当前位置。intread()读一个字符。intread(char[] cbuf, int off, int len)将字符读入数组的一部分。StringreadLine()阅读一行文字。voidreset()将流重置为最新标记。voidsetLineNumber(int lineNumber)设置当前行号。longskip(long n)跳过字符。-  
               
声明方法的类 java.io.BufferedReader
lines, markSupported, ready 
-  
               
声明方法的类 java.io.Reader
close, nullReader, read, read, transferTo 
 -  
               
 
 -  
             
 
-  
        
       
-  
             
方法详细信息
-  
setLineNumber
public void setLineNumber(int lineNumber)
设置当前行号。- 参数
 -  
              
lineNumber- 指定行号的int - 另请参见:
 -  
              
getLineNumber() 
 
-  
getLineNumber
public int getLineNumber()
获取当前行号。- 结果
 - 当前行号
 - 另请参见:
 -  
              
setLineNumber(int) 
 
-  
read
public int read() throws IOException- 重写:
 -  
              
read类BufferedReader - 结果
 - 字符读取,如果已到达流的末尾,则返回-1
 - 异常
 -  
              
IOException- 如果发生I / O错误 
 
-  
read
public int read(char[] cbuf, int off, int len) throws IOException将字符读入数组的一部分。 每当读取line terminator时 ,当前行号将递增。- 重写:
 -  
              
read类BufferedReader - 参数
 -  
              
cbuf- 目标缓冲区 -  
              
off- 开始存储字符的偏移量 -  
              
len- 要读取的最大字符数 - 结果
 - 读取的字节数,如果已到达流的末尾,则返回-1
 - 异常
 -  
              
IOException- 如果发生I / O错误 -  
              
IndexOutOfBoundsException- 如果发生I / O错误 
 
-  
readLine
public String readLine() throws IOException
阅读一行文字。 每当读取line terminator时 ,当前行号递增。- 重写:
 -  
              
readLine在类BufferedReader - 结果
 - 
               包含该行内容的字符串,如果已到达流末尾,则不包括任何 
              line termination characters或 
              
null - 异常
 -  
              
IOException- 如果发生I / O错误 - 另请参见:
 -  
              
Files.readAllLines(java.nio.file.Path, java.nio.charset.Charset) 
 
-  
skip
public long skip(long n) throws IOException跳过字符。- 重写:
 -  
              
skip在类BufferedReader - 参数
 -  
              
n- 要跳过的字符数 - 结果
 - 实际跳过的字符数
 - 异常
 -  
              
IOException- 如果发生I / O错误 -  
              
IllegalArgumentException- 如果n为负数 
 
-  
mark
public void mark(int readAheadLimit) throws IOException标记流中的当前位置。 对reset()的后续调用将尝试将流重新定位到此点,并且还将适当地重置行号。- 重写:
 -  
              
mark在类BufferedReader - 参数
 -  
              
readAheadLimit- 限制仍保留标记时可读取的字符数。 读取这么多字符后,尝试重置流可能会失败。 - 异常
 -  
              
IOException- 如果发生I / O错误 
 
-  
reset
public void reset() throws IOException将流重置为最新标记。- 重写:
 -  
              
reset在类BufferedReader - 异常
 -  
              
IOException- 如果尚未标记流,或者标记已失效 
 
 -  
 
 -