java 读取下一行_java - 我怎样才能让我的扫描仪读取文件中的下一行? - SO中文参考 - www.soinside.com...

我打印出一个txt文件的内容,跳过那些文件中的任何数字。

我使用看起来像这样的文件:

一二3三,四

五六7 8

我一直在使用input2.next()或input2.nextline()是System.out.print后(令牌)试过,但我要么得到一个错误或不准确的读取下一行。

import java.util.*;

import java.io.*;

public class ScannerClass {

public static void main(String[] args) throws FileNotFoundException {

System.out.print("Enter file name and extension: ");

Scanner input = new Scanner(System.in);

File file = new File(input.next());

Scanner input2 = new Scanner(file);

String token;

//this will print out the first line in my txt file, I am having trouble

//reading the next line in the file!

while ((token = input2.findInLine("[\\p{Alpha}\\p{javaWhitespace}]+")) != null) {

System.out.print(token);

}

}

}

输出是:

一二三四

我想看到的是整个txt文件少任何数字,如:

一二三四

五六8

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值