import java.io.*; import java.util.Scanner; public class Nombres { public static void main(String args[]) throws IOException { String name1, name2=null; Scanner s = new Scanner(new File("lista.txt"), "ISO-8859-1"); Extractor e = new Extractor(s); while(e.quedanNombres()){ System.out.println(e.getRealName()); } } } class Extractor { public Extractor(Scanner s) { this.s = s; } public boolean quedanNombres() { return s.hasNextLine(); } public String getRealName() { String delimitador="[ \t\n]"; String linea, aPaterno, aMaterno, name1, name2; if (!quedanNombres()) return null; linea = s.nextLine(); Scanner l = (new Scanner(linea)).useDelimiter(delimitador); aPaterno = l.next(); aMaterno = l.next(); name1 = l.next(); if (l.hasNext())name2 = l.next(); //few have just one name. else name2=""; return name1+" "+name2+" "+aPaterno+" "+aMaterno; } private Scanner s; }