Java - How to traverse a file.txt and order it?

0

Good day to all and thanks for answering. I am doing a program in which a file.txt is handled, it is a phone book that stores the name surnames and the telephone number of the person, however I have no idea how to make said agenda alphabetically order the data that is inside the file that I fill in previously or how to put a limit on the data that we can save. Help!

They are stored like this:

marian # jaimes # garcia # 78945631   
pedro # estrada # lopez # 7451365898   
lady # ayala # peres # 13546789    
susana # gomez # corona # 123456   
guillermo  # guadarrama # sanchez # 7894563

how to order them? Excuse me, I'm very new to all this.

    
asked by Raymundo Estrada 06.06.2018 в 09:46
source

1 answer

0
public void ordenarFichero(String rutaAlFichero) throws IOException{
    Path path = Paths.get(rutaAlFichero);
    List<String> lineas = Files.readAllLines(path);
    lineas = lineas.stream()
                    .sorted((o1,o2)->o1.compareTo(o2))//Aquí podrías poner un criterio de ordenación diferente
                    .collect(Collectors.toList());
}
    
answered by 06.06.2018 в 10:04