Actividad 1.2 - Tratamiento fichero txt con objetos
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
bin/
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings/
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package org.palomafp.aadd.gdo;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.gdo.vo.Continente;
|
||||||
|
import org.palomafp.aadd.gdo.vo.Pais;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
imprimirInformacionPaises("C:\\Users\\gonza\\aadd\\fic02\\informacion_paises.txt");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void imprimirInformacionPaises(String rutaFichero) {
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(rutaFichero))) {
|
||||||
|
String linea;
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
|
||||||
|
if (linea.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
} else if (linea.startsWith("-")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] campos = linea.split(",");
|
||||||
|
|
||||||
|
String codContinente = campos[0].replace("\"", "");
|
||||||
|
String idStr = campos[1].replace("\"", "");
|
||||||
|
String nombrePais = campos[2].replace("\"", "");
|
||||||
|
String capital = campos[3].replace("\"", "");
|
||||||
|
|
||||||
|
Continente c = new Continente();
|
||||||
|
c.setCodigo(codContinente);
|
||||||
|
|
||||||
|
Pais p = new Pais();
|
||||||
|
p.setIdentificador(Integer.parseInt(idStr));
|
||||||
|
p.setNombre(nombrePais);
|
||||||
|
p.setCapital(capital);
|
||||||
|
p.setContinente(c);
|
||||||
|
|
||||||
|
System.out.println(p);
|
||||||
|
|
||||||
|
System.out.println("INSERT INTO T_PAIS (cod_continente, identificador, capital, nombre_pais) VALUES (" + idStr + ", '" + codContinente + "', '"+ capital + "', '"+ nombrePais + "');");
|
||||||
|
System.out.println("-------------------------------------------------------------------------------------------------------------------------");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.palomafp.aadd.gdo.vo;
|
||||||
|
|
||||||
|
public class Continente {
|
||||||
|
|
||||||
|
private String codigo;
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
public String getCodigo() {
|
||||||
|
return codigo;
|
||||||
|
}
|
||||||
|
public void setCodigo(String codigo) {
|
||||||
|
this.codigo = codigo;
|
||||||
|
}
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Continente [codigo=" + codigo + ", nombre=" + nombre + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package org.palomafp.aadd.gdo.vo;
|
||||||
|
|
||||||
|
public class Pais {
|
||||||
|
|
||||||
|
private int identificador;
|
||||||
|
private String nombre;
|
||||||
|
private String capital;
|
||||||
|
private Continente continente;
|
||||||
|
|
||||||
|
public int getIdentificador() {
|
||||||
|
return identificador;
|
||||||
|
}
|
||||||
|
public void setIdentificador(int identificador) {
|
||||||
|
this.identificador = identificador;
|
||||||
|
}
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
public String getCapital() {
|
||||||
|
return capital;
|
||||||
|
}
|
||||||
|
public void setCapital(String capital) {
|
||||||
|
this.capital = capital;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Continente getContinente() {
|
||||||
|
return continente;
|
||||||
|
}
|
||||||
|
public void setContinente(Continente continente) {
|
||||||
|
this.continente = continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Pais [identificador=" + identificador + ", nombre=" + nombre + ", capital=" + capital + ", continente="
|
||||||
|
+ continente + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user