generated from programacionThiar/plantilla_iesthiar-maven-21
Ejercicio B Completos
This commit is contained in:
@@ -4,7 +4,11 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Ejercicio_B4 {
|
||||
@@ -29,8 +33,9 @@ public class Ejercicio_B4 {
|
||||
File fileApellidos = new File("target/classes/iesthiar/Documentos/usa_apellidos.txt");
|
||||
|
||||
// ArrayList con los datos de los ficheros de lectura
|
||||
ArrayList<String> listaNombres = leerDatosFichero(fileNombres);
|
||||
//ArrayList<String> listaNombres = leerDatosFichero(fileNombres);
|
||||
ArrayList<String> listaApellidos = leerDatosFichero(fileApellidos);
|
||||
List<String> listaNombres=Files.readAllLines(Paths.get("target/classes/iesthiar/Documentos/usa_nombres.txt"));
|
||||
|
||||
// Generamos el nombre y apellido aleatoriamente y lo escribimos en el fichero
|
||||
try ( // FileWriter para escritura
|
||||
@@ -56,7 +61,7 @@ public class Ejercicio_B4 {
|
||||
|
||||
// Devuelve un ArrayList con los datos leidos del fichero
|
||||
public static ArrayList<String> leerDatosFichero(File f) throws FileNotFoundException {
|
||||
try ( Scanner lector = new Scanner(f);){
|
||||
try ( Scanner lector = new Scanner(f);){
|
||||
ArrayList<String> lista = new ArrayList<>();
|
||||
while (lector.hasNext()) {
|
||||
lista.add(lector.nextLine());
|
||||
|
||||
Reference in New Issue
Block a user