-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExceptionChecked.java
More file actions
42 lines (38 loc) · 1.06 KB
/
ExceptionChecked.java
File metadata and controls
42 lines (38 loc) · 1.06 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
package com.mahesh.exceptionHandelling;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
public class ExceptionChecked {
public static void main(String args[]) {
String content = "Hello Vishwa";
FileInputStream fis = null;
try {
fis = new FileInputStream("D:/java programs/vishwa.txt");
} catch (FileNotFoundException fnfe) {
System.out.println("The specified file is not "
+ "present at the given path");
}
int k;
try {
File file = new File("D:/java programs/vishwa.txt");
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
System.out.println("Done");
while ((k = fis.read()) != -1) {
System.out.print((char) k);
}
fis.close();
} catch (IOException ioe) {
System.out.println("I/O error occurred: " + ioe);
}
}
}