-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClase Java 28.java
More file actions
48 lines (27 loc) · 1.51 KB
/
Clase Java 28.java
File metadata and controls
48 lines (27 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//--------------------------------------------------------------|
//CONTENIDO: Leer desde un Fichero
//--------------------------------------------------------------|
package clase.java.pkg28;
import java.io.File;
//------------------------------------|
import java.io.FileNotFoundException;// Permite que el programa maneje excepciones relacionadas con la ausencia de un archivo.
//------------------------------------|
//------------------------|
import java.util.Scanner;// Permite analizar y leer entradas de texto desde varias fuentes.
//------------------------|
public class ClaseJava28 {
public static void main(String[] args) {
try {
File file = new File("Fichero.txt");
Scanner scanner = new Scanner(file); // "scanner" se utiliza para leer datos de diversas fuentes.
while (scanner.hasNextLine()) { // "hasNextLine" se utiliza para verificar si hay una línea completa de entrada disponible para ser leída.
String data = scanner.nextLine(); // "nextLine" se utiliza para leer una línea completa de texto.
System.out.println(data);
}
scanner.close();
} catch (FileNotFoundException e) {
System.out.println("El fichero no fue encontrado.");
e.printStackTrace();
}
}
}