Nuevo commit
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.palomafp.aadd.ss.dao.impl;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
@@ -21,7 +22,7 @@ public class ContinenteDaoCSV implements IContinenteDAO {
|
||||
try{
|
||||
// 1. Usamos Path y Files en lugar de BufferedReader
|
||||
//Path rutaNio = Path.of(ruta);
|
||||
List<String> todasLasLineas = Files.readAllLines(rutaNio);
|
||||
List<String> todasLasLineas = Files.readAllLines(rutaNio, StandardCharsets.UTF_8);
|
||||
|
||||
boolean primerLinea = true;
|
||||
for(String linea : todasLasLineas) {
|
||||
@@ -64,11 +65,11 @@ public class ContinenteDaoCSV implements IContinenteDAO {
|
||||
//Path rutaNio = Path.of(ruta);
|
||||
String lineaNueva = "2026" + separador + continente.getCodigo() + separador + continente.getNombre();
|
||||
// Files.write añade la línea directamente (el List.of crea una lista de 1 solo elemento)
|
||||
Files.write(rutaNio, List.of(lineaNueva), StandardOpenOption.APPEND);
|
||||
Files.write(rutaNio, List.of(lineaNueva),StandardCharsets.UTF_8 , StandardOpenOption.APPEND);
|
||||
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error al insertat el continente. " + e.getMessage());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -129,7 +130,7 @@ public class ContinenteDaoCSV implements IContinenteDAO {
|
||||
lineasAEscribir.add("2026" + separador + c.getCodigo() + separador + c.getNombre());
|
||||
}
|
||||
// Si no le ponemos APPEND, Files.write borra el archivo y lo escribe entero de nuevo (¡Justo lo que queremos!)
|
||||
Files.write(rutaNio, lineasAEscribir);
|
||||
Files.write(rutaNio, lineasAEscribir, StandardCharsets.UTF_8);
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error al actualizar el fichero: " + e.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user