代码如下:
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
class ReadLine
{
public static void main(String[] args) throws IOException
{
FileReader fr = new FileReader("E:/java task/cookie reader/荷塘月色.txt");//FileReader 用于读文件
BufferedReader br = new BufferedReader(fr);//使用缓冲区的方法将数据读入到缓冲区中
String str;
int i=1;
while((str = br.readLine()) != null)
{
System.out.println( "["+i+"]:" + str);
System.out.println( );
switch(i)
{
case 5:
System.out.println("------------------------ page 1 ------------------------");
System.out.println( );
break;
case 10:
System.out.println("------------------------- page 2 ------------------------");
System.out.println( );
break;
case 15:
System.out.println("------------------------- page 2 ------------------------");
System.out.println( );
break;
default:
break;
}
i=i+1;
}
}
}
结果如下: