-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionDemo.java
More file actions
36 lines (31 loc) · 829 Bytes
/
Copy pathExceptionDemo.java
File metadata and controls
36 lines (31 loc) · 829 Bytes
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
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class ExceptionDemo {
public static void main(String[] args) {
FileInputStream fin = null;
try {
fin = new FileInputStream("Student.txt");
System.out.println("Related to file.");
int a[] = { 1, 2, 3, 4, 5 };
for (int i = 0; i <= 5; i++) {
System.out.println(a[i]);
}
} catch (FileNotFoundException e) {
System.err.println("File not Found" + e);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Array Index Issue");
} catch (Exception e) {
System.out.println(e);
} finally {
try {
if (fin != null)
fin.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("After File Input");
System.out.println("Last");
}
}