1. java.util.Scanner
!
A partir do Java 5.0;
!
Facilita a leitura de dados:
!
!
Divide em tokens com useDelimiter(String);
!
Faz leitura regionalizada com useLocale(Locale);
!
23
Construtores podem receber File, InputStream,
Reader e String;
Obtém dados diretamente em seus tipos, com next(),
nextLine(), nextBoolean(), nextInt(), nextDouble(),
etc.
2. Exemplo de Uso de Scanner
public
void
LerScanner(String
filename)
throws
IOException
{
Scanner
sc
=
new
Scanner(new
File(filename));
String
texto=new
String();
while(sc.hasNext())
texto
+=
sc.nextLine()+
"n";
sc.close();
System.out.println(texto);
}
//String
filename="texto.txt";
24