- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFileExc.java
More file actions
Latest commit
29 lines (29 loc) · 687 Bytes
/
Copy pathFileExc.java
File metadata and controls
29 lines (29 loc) · 687 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
// Java Program that read from a file and write to file by handling all file related exceptions
importjava.io.*;
classFileExc
{
publicstaticvoidmain(Stringargs[])
{
try
{
FileReaderfin=newFileReader("testing.txt");
FileWriterfout=newFileWriter("copy.txt");
inti;
while((i=fin.read())!=-1)
{
System.out.println((char) i);
fout.write(i);
}
fin.close();
fout.close();
}
catch(FileNotFoundExceptione)
{
System.out.println(e.getMessage());
}
catch(IOExceptione)
{
System.out.println(e.getMessage());
}
}
}