I am working on a program that obtains data from a text file, obtains only the first 100 and has a method that orders from the first to the last or vice versa and another that searches for a specific name in the file.
This is what I have at the moment.
import java.util.ArrayList;
import java.util.Scanner;
import java.io.File;
public class distritos
{
public static void main(String[] args)
{
Scanner entrada;
File archivo;
String a;
String linea;
ArrayList<Double> array = new ArrayList<Double>();
try
{
entrada = new Scanner("Texto.txt");
a = entrada.nextLine();
archivo = new File(a);
entrada = new Scanner(archivo);
int comienzo = 0;
while(entrada.hasNextLine() && comienzo < 100)
{
linea = entrada.nextLine();
System.out.println(linea);
comienzo++;
}
}
catch(Exception e)
{
}
}
}
I try it and it works well, it gets the first 100 lines and prints them, however, I have problems when it comes to ordering it and I do not know where to start.