Segundo commit Fichero07
This commit is contained in:
@@ -12,10 +12,11 @@ import java.util.List;
|
||||
|
||||
import org.palomafp.aadd.ss.dao.IContinenteDAO;
|
||||
import org.palomafp.aadd.ss.model.Continente;
|
||||
|
||||
import org.palomafp.aadd.ss.gestores.GestorConfiguracion;
|
||||
public class ContinenteDaoCSV implements IContinenteDAO {
|
||||
|
||||
static String ruta = "C:\\Users\\sajed\\Desktop\\2DAM\\AADD\\aadd\\fic04\\informacion_continentes.csv";
|
||||
private String ruta = GestorConfiguracion.getRutaFicheroContinente();
|
||||
private String separador = GestorConfiguracion.getSeparadorCsvFicheroContinente();
|
||||
|
||||
@Override
|
||||
public List<Continente> obtenerTodos() {
|
||||
@@ -27,7 +28,7 @@ public class ContinenteDaoCSV implements IContinenteDAO {
|
||||
}
|
||||
while(br.ready()) {
|
||||
String linea = br.readLine();
|
||||
String [] datos = linea.split("#");
|
||||
String [] datos = linea.split(separador);
|
||||
listaContinentes.add(new Continente(datos[1].trim(), datos[2].trim()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -58,7 +59,7 @@ public class ContinenteDaoCSV implements IContinenteDAO {
|
||||
try(BufferedWriter bw = new BufferedWriter(new FileWriter(ruta, true))){
|
||||
//Salta de linea
|
||||
bw.newLine();
|
||||
bw.write("2026" + "#" + continente.getCodigo() + "#" + continente.getNombre());
|
||||
bw.write("2026" + separador + continente.getCodigo() + separador + continente.getNombre());
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error al insertat el continente. " + e.getMessage());
|
||||
@@ -115,7 +116,7 @@ public class ContinenteDaoCSV implements IContinenteDAO {
|
||||
private void reescribirFichero(List<Continente> lista) {
|
||||
try(BufferedWriter bw = new BufferedWriter(new FileWriter(ruta, false))){
|
||||
for(Continente c : lista) {
|
||||
bw.write("2026" + "#" + c.getCodigo() + "#" + c.getNombre());
|
||||
bw.write("2026" + separador + c.getCodigo() + separador + c.getNombre());
|
||||
bw.newLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user