?? linenumberdemo.java
字號:
//LineNumberDemo.java
import java.io.*;
public class LineNumberDemo
{
public static void main(String args[])throws IOException{
//定義數(shù)據(jù)輸入流
DataInputStream dis;
//定義文件輸入流
FileInputStream fis;
//定義緩沖區(qū)輸入流
BufferedInputStream bis;
//定義行號輸入流
LineNumberInputStream lnis;
String strLine;
try
{
//創(chuàng)建文件輸入流對象,與實際文件相連
fis = new FileInputStream("d:\\destnation.txt");
//根據(jù)文件輸入流對象創(chuàng)建緩沖區(qū)輸入流
bis = new BufferedInputStream(fis);
//根據(jù)緩沖區(qū)輸入流對象創(chuàng)建行號輸入流
lnis = new LineNumberInputStream(bis);
//根據(jù)行號輸入流創(chuàng)建數(shù)據(jù)輸入流
dis = new DataInputStream(lnis);
//從數(shù)據(jù)輸入流中讀數(shù)據(jù)
while((strLine=dis.readLine())!=null)
{
//從行號輸入流中取得行號
int nLineNumber = lnis.getLineNumber();
//打印出行號和當(dāng)前行內(nèi)容
System.out.println(nLineNumber+":"+strLine);
}
dis.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -