1
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-27">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Ficheros_02</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=26
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=26
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=26
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,84 @@
|
|||||||
|
package org.palomafp.aadd.rif;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.palomafp.aadd.rif.vo.Continente;
|
||||||
|
import org.palomafp.aadd.rif.vo.Pais;
|
||||||
|
|
||||||
|
public class AppPrincipal {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Sustituye "IsidoroNM" por tu ruta o usuario real según corresponda
|
||||||
|
String rutaFichero = "C:\\Users\\alumnoT\\aadd\\fic02.txt";
|
||||||
|
|
||||||
|
imprimirInformacionPaises(rutaFichero);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void imprimirInformacionPaises(String ruta) {
|
||||||
|
File fichero = new File(ruta);
|
||||||
|
|
||||||
|
if (!fichero.exists()) {
|
||||||
|
System.err.println("El fichero no existe en la ruta especificada: " + ruta);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(fichero))) {
|
||||||
|
String linea;
|
||||||
|
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
// Limpiar espacios en blanco al inicio y al final
|
||||||
|
linea = linea.trim();
|
||||||
|
|
||||||
|
// Las líneas vacías o aquellas que comienzan por # no se procesan ni imprimen
|
||||||
|
if (linea.isEmpty() || linea.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Descomponer la línea. Supongamos separación por punto y coma ';' o coma ','
|
||||||
|
// Ejemplo esperado de línea: 93;Arabia Saudita;Riad;03
|
||||||
|
String[] datos = linea.split(",");
|
||||||
|
|
||||||
|
if (datos.length >= 4) {
|
||||||
|
try {
|
||||||
|
String codContinente = datos[0].replace("\"", "").trim();
|
||||||
|
String idStr = datos[1].replace("\"", "").trim();
|
||||||
|
String nombrePais = datos[2].replace("\"", "").trim();
|
||||||
|
String capital = datos[3].replace("\"", "").trim();
|
||||||
|
|
||||||
|
int id = Integer.parseInt(idStr);
|
||||||
|
|
||||||
|
// Instanciamos el objeto Continente de acuerdo con la estructura solicitada
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codContinente);
|
||||||
|
continente.setNombre(null); // Según la salida muestra: nombre=null
|
||||||
|
|
||||||
|
// Instanciamos el objeto País (Bean)
|
||||||
|
Pais pais = new Pais();
|
||||||
|
pais.setIdentificador(id);
|
||||||
|
pais.setNombre(nombrePais);
|
||||||
|
pais.setCapital(capital);
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
// 1. Imprimir la representación de los objetos tipo Bean
|
||||||
|
System.out.println(pais.toString());
|
||||||
|
|
||||||
|
// 2. Imprimir la sentencia SQL correspondiente con el formato esperado
|
||||||
|
System.out.printf("INSERT INTO T_PAIS (cod_continente, identificador, capital, nombre_pais) VALUES (%d, '%s', '%s', '%s');\n",
|
||||||
|
pais.getIdentificador(),
|
||||||
|
pais.getContinente().getCodigo(),
|
||||||
|
pais.getCapital(),
|
||||||
|
pais.getNombre());
|
||||||
|
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.err.println("Error de formato en el identificador numérico de la línea: " + linea);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Ocurrió un error al leer el fichero de datos: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package org.palomafp.aadd.rif.vo;
|
||||||
|
|
||||||
|
public class Continente {
|
||||||
|
|
||||||
|
private String codigo;
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
public Continente() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Continente (String codigo, String nombre) {
|
||||||
|
this.codigo = codigo;
|
||||||
|
this.nombre = 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,55 @@
|
|||||||
|
package org.palomafp.aadd.rif.vo;
|
||||||
|
|
||||||
|
public class Pais {
|
||||||
|
private int identificador;
|
||||||
|
private String nombre;
|
||||||
|
private String capital;
|
||||||
|
private Continente continente;
|
||||||
|
|
||||||
|
public Pais() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pais(int identificador, String nombre, String capital, Continente continente) {
|
||||||
|
this.identificador = identificador;
|
||||||
|
this.nombre = nombre;
|
||||||
|
this.capital = capital;
|
||||||
|
this.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