Skip to content

Instantly share code, notes, and snippets.

@pablohdzvizcarra
Created March 8, 2025 19:45
Show Gist options
  • Save pablohdzvizcarra/e10ad2c07556eb924f54cc79021735f6 to your computer and use it in GitHub Desktop.
Save pablohdzvizcarra/e10ad2c07556eb924f54cc79021735f6 to your computer and use it in GitHub Desktop.
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Example2 {
public static void main(String[] args) {
String filePath = "data.txt";
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (FileNotFoundException e) {
System.out.println("The file cannot be found: " + e.getMessage());
} catch (IOException e) {
System.out.println("An error ocurred reading the file: " + e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment