-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathException8.java
More file actions
24 lines (24 loc) · 801 Bytes
/
Exception8.java
File metadata and controls
24 lines (24 loc) · 801 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
import java.io.*;
public class Exception8 {
public static void main(String[] args) {
try {
FileOutputStream f=new FileOutputStream("abcd.txt");
String content="Hello World";
f.write(content.getBytes());
// byte arr[]=content.getBytes();
// f.write(arr);
f.close();
System.out.println("File Written Successfully");
FileInputStream file=new FileInputStream("abcd.txt");
int ch=file.read();
while(ch!=-1) {
System.out.print((char)ch);
ch=file.read();
}
} catch(FileNotFoundException e) {
System.out.println("File not found.");
} catch(Exception e) {
e.printStackTrace();
}
}
}