package zhidao;
import java.io.File;
import java.util.LinkedList;
import java.util.Scanner;
public class Roobit
{
public static void main ( String[] args ) throws Exception
{
LinkedListhosts = new LinkedList ();
Scanner scanner = new Scanner (new File ("hosts.txt"));
String regex = "^host[\\s\\=]+[^\r\n]+$";
while (scanner.hasNextLine ())
{
String line = scanner.nextLine ();
if (line.matches (regex))
{
hosts.add (line);
}
}
scanner.close ();
for ( String string : hosts )
{
System.out.println (string);
}
}
}
用工具栏Scanner,里面的正则筛选构造函数即可,一下就可以读到host信息