java怎么用Scanner读取一个文件,然后只显示文件中的字母,删除数字与标点
1个回答
展开全部
package p1;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class FootballClub
{
private static void filter ( String fileName )
{
Scanner scanner = null;
String reg = "(?i)[^a-z]";
try
{
scanner = new Scanner (new File (fileName));
while (scanner.hasNextLine ())
{
String line = scanner.nextLine ().replaceAll (reg, "");
System.out.println (line);
}
scanner.close ();
}
catch (FileNotFoundException e)
{
e.printStackTrace ();
}
}
public static void main ( String[] args )
{
filter ("test.ini");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询