-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDemo1.java
More file actions
30 lines (24 loc) · 854 Bytes
/
Copy pathDemo1.java
File metadata and controls
30 lines (24 loc) · 854 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
import java.io.File;
import java.io.IOException;
public class Demo1 {
public static void main(String[] args) {
// Example Create a New File in Java
File file = new File("D:\\JavaWeekEnd10to12\\Abcd.txt");
try{
// try is a block where exception can be occured
file.createNewFile(); // throw new IOException
System.out.println("File Created...");
int e = 10/0; // throw new ArithmeticException(); (UnChecked)
// Checked Exception Treatement Must be on Compile time
}
catch(ArithmeticException e){
System.out.println("U Divide a number with zero , Kindly COntact to System Admin");
}
catch(IOException e){
System.out.println("File Path Might Be Wrong or Not Exist , Kindly COntact to System Admin");
}
catch(Exception e){
System.out.println("Some Other Problem Raised , Contact to Software Team");
}
}
}