Incluye try-with-resources
This commit is contained in:
@@ -34,7 +34,7 @@ public class GestorMapaMundi {
|
|||||||
System.out.println(pais);
|
System.out.println(pais);
|
||||||
|
|
||||||
System.out.println("----------------------------------------------------");
|
System.out.println("----------------------------------------------------");
|
||||||
|
|
||||||
String codigoContinente = "04";
|
String codigoContinente = "04";
|
||||||
List<Pais> listaPaises = app.obtenerPaisesPorContinente(codigoContinente);
|
List<Pais> listaPaises = app.obtenerPaisesPorContinente(codigoContinente);
|
||||||
// Imprimir la información de los paises en la consola.
|
// Imprimir la información de los paises en la consola.
|
||||||
@@ -48,9 +48,9 @@ public class GestorMapaMundi {
|
|||||||
Pais paisEncontrado = null;
|
Pais paisEncontrado = null;
|
||||||
|
|
||||||
File ficheroPaises = new File(RUTA_FICHERO);
|
File ficheroPaises = new File(RUTA_FICHERO);
|
||||||
BufferedReader reader = null;
|
|
||||||
try {
|
try (BufferedReader reader = new BufferedReader(new FileReader(ficheroPaises));) {
|
||||||
reader = new BufferedReader(new FileReader(ficheroPaises));
|
|
||||||
while (reader.ready()) {
|
while (reader.ready()) {
|
||||||
String linea = reader.readLine();
|
String linea = reader.readLine();
|
||||||
|
|
||||||
@@ -79,11 +79,6 @@ public class GestorMapaMundi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
try {
|
|
||||||
reader.close();
|
|
||||||
} catch (IOException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,9 +89,9 @@ public class GestorMapaMundi {
|
|||||||
List<Pais> listaPaisesEncontrados = null;
|
List<Pais> listaPaisesEncontrados = null;
|
||||||
|
|
||||||
File ficheroPaises = new File(RUTA_FICHERO);
|
File ficheroPaises = new File(RUTA_FICHERO);
|
||||||
BufferedReader reader = null;
|
|
||||||
try {
|
try (BufferedReader reader = new BufferedReader(new FileReader(ficheroPaises));) {
|
||||||
reader = new BufferedReader(new FileReader(ficheroPaises));
|
|
||||||
while (reader.ready()) {
|
while (reader.ready()) {
|
||||||
String linea = reader.readLine();
|
String linea = reader.readLine();
|
||||||
|
|
||||||
@@ -129,11 +124,6 @@ public class GestorMapaMundi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
try {
|
|
||||||
reader.close();
|
|
||||||
} catch (IOException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user