Mittwoch lesson
This commit is contained in:
parent
e0efeb82ef
commit
8901dea11b
61 changed files with 663 additions and 0 deletions
28
Code/Steiner/tryCatchTask/src/App.java
Normal file
28
Code/Steiner/tryCatchTask/src/App.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
import java.io.*;
|
||||
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
readFile("test.txt");
|
||||
} catch (FileNotFoundException e) {
|
||||
System.err.println("Error: The file was not found. Please check the file path.");
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error: An I/O error occurred while reading the file.");
|
||||
} catch (Exception e) {
|
||||
System.err.println("An unexpected error occurred: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void readFile(String fileName) throws IOException {
|
||||
FileReader f = new FileReader(fileName);
|
||||
try {
|
||||
int c;
|
||||
while ((c = f.read()) != -1) {
|
||||
System.out.print((char) c);
|
||||
}
|
||||
} finally {
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue