segundo
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
module Actividad1_Jilai {
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package org.palomafp.aadd.jx; // Reemplaza 'xxx' por tus iniciales
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public class AppPrincipal {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
// Colocaremos la ruta que tengamos, en mi caso la cuenta de usuario es alumnoT
|
||||
|
||||
String rutaCarpeta = "C:\\Users\\alumnoT\\aadd\\fic01\\";
|
||||
String nombreFichero = "informacion_paises.txt";
|
||||
File fichero = new File(rutaCarpeta + nombreFichero);
|
||||
|
||||
|
||||
BufferedReader bufferLectura = null;
|
||||
|
||||
|
||||
try {
|
||||
|
||||
// Comprobamos si existe el fichero
|
||||
if (!fichero.exists()) {
|
||||
System.out.println("No se encuentra el fichero en la ruta: " + fichero.getAbsolutePath());
|
||||
return;
|
||||
}
|
||||
|
||||
// Inicializamos la lectura y se guardara en un buffer
|
||||
|
||||
bufferLectura = new BufferedReader(new FileReader(fichero));
|
||||
String linea;
|
||||
|
||||
System.out.println("--- INICIO ---");
|
||||
|
||||
// vAmos a recorrer el fichero paso a paso
|
||||
while ((linea = bufferLectura.readLine()) != null) {
|
||||
|
||||
// Filtramos únicamente la línea que queramos por ejemplo que empiece por #
|
||||
if (linea.trim().startsWith("#") || linea.trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Vamos a seperar con comas para que se entiendan las cosas
|
||||
String[] campos = linea.split(",");
|
||||
|
||||
if (campos.length >= 4) {
|
||||
|
||||
// Ejemplo de limpieza de comillas si el formato de los campos las incluye
|
||||
String idCiclo = campos[0].replace("\"", "").trim();
|
||||
String nombreCiclo = campos[2].replace("\"", "").trim();
|
||||
|
||||
int anio = 2000;
|
||||
String familia = (idCiclo.length() >= 3) ? idCiclo.substring(0, 3) : idCiclo;
|
||||
|
||||
// Imprimimos por consola el literal requerido por la actividad
|
||||
System.out.println("INSERT INTO T_PAIS VALUES ('" + idCiclo + "', '" + nombreCiclo + "', " + anio + ", '" + familia + "');");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("--- FIN ---");
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error de E/S al leer el fichero: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
|
||||
|
||||
try {
|
||||
if (bufferLectura != null) {
|
||||
bufferLectura.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error al cerrar el fichero: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user