-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile_Handling_Copy_From_one_To_Another.java
More file actions
36 lines (31 loc) · 1.12 KB
/
File_Handling_Copy_From_one_To_Another.java
File metadata and controls
36 lines (31 loc) · 1.12 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
package practicetime;
import java.io.*;
public class File_Handling_Copy_From_one_To_Another
{
public static void main(String[] args)
{
File infile = new File("infile.txt");
File outfile = new File("Outfile.txt");
FileReader fr=null;
FileWriter fw=null;
try{
fr = new FileReader(infile);
fw = new FileWriter(outfile);
int ch=0;
//FileReader Class which is subclass of InputSteamReader//InputStreamReader class converts Strings or character data//into Byte which are in form of integers. //so ch is of int typewhile((ch=fr.read())!=-1){ //-1 indicates end-of-file (eof)
fw.write(ch);
}
catch(IOException e)
{
System.out.println(e);
System.exit(-1);
}
finally{
try{
fr.close();
fw.close();
}
catch(IOException e){}
}
}
}