java从指定行开始,读取的内容(自己弄的拙劣方法)

本文介绍了一种使用Java从特定行开始读取大文件的方法,通过实例演示如何跳过前几行并打印剩余内容,适用于处理大型文本文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下面是部分程序展示:

public static void main(String[] args) {
		File f=new File("00data/4thStep_sr_ready/wikiNames_next/1.htm");
		FileReader fReader;
		try {
			fReader = new FileReader(f);
			
			BufferedReader lineNum=new BufferedReader(fReader);
			/*int num=5999;
			//LineNumberReader lineNum=new LineNumberReader(fReader);
			lineNum.setLineNumber(num);
			//上面这个函数只是修改了行号,读取的时候,还是按照原来的顺序读取文件内容。
			
			System.out.println(lineNum.readLine());//测试!!!!!!
			 */			
			
			String s=null;
			int n=9559;//设置起始读取数据的行号
			for(int i=1;i<n;i++){
				lineNum.readLine();
			}
			while((s=lineNum.readLine())!=null){
				System.out.println(n+"内容为:"+s);
				n++;
                                //Thread.sleep(1000);
			}
			
		} catch (Exception e) {e.printStackTrace();}
	}


转载于:https://my.oschina.net/airship/blog/324776

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值