¿Cómo hacer que un programa me de la información de un fichero?
El programa me debería dar la información dentro del fichero pero en cambio solo me da el numero de líneas
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class PuenteDiciembreAlfonsoVillanuevaRivero {
/*
public static String[] lectura_datos_csv() throws IOException{
String[] linea = leer_fichero_array("alumnosFP.txt");;
return linea;
}
*/
public static int contar_numero_lineas_fichero (String nombre_fichero) throws IOException {
int contador = 0;
File fichero = new File (nombre_fichero);
FileReader fr = new FileReader(fichero);
BufferedReader br = new BufferedReader(fr);
while(br.readLine() != null) {
contador++;
}
return contador;
}
public static String[] leer_fichero_array (String nombre_fichero) throws IOException {
int numero_lineas = contar_numero_lineas_fichero(nombre_fichero);
String[] lineas = new String[numero_lineas];
File fichero = new File(nombre_fichero);
Scanner sc = new Scanner(fichero);
for(int i = 0; i<lineas.length; i++) {
lineas[i] = sc.nextLine();
}
return lineas;
}
public static void main(String[] args) throws IOException {
System.out.println("" );
String[] lineas = leer_fichero_array("alumnosFP.txt");
System.out.println("elementos array: " + lineas.length);
}
}