我打印出一个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