-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileMergeAlt.java
44 lines (39 loc) · 1.09 KB
/
FileMergeAlt.java
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
43
44
import java.io.*;
public class FileMergeAlt
{
public static void main(String args[])
{
try
{
FileReader f1 = new FileReader("f1.txt");
BufferedReader bf1 = new BufferedReader(f1);
FileReader f2 = new FileReader("f2.txt");
BufferedReader bf2 = new BufferedReader(f2);
FileWriter f = new FileWriter("f.txt");
String str;
while((str=bf1.readLine())!=null)
{
f.write(str);
f.write('\n');
if((str=bf2.readLine()) != null)
{
f.write(str);
f.write('\n');
}
}
while((str=bf2.readLine()) != null)
{
f.write(str);
f.write('\n');
}
System.out.println("Files are merged alternatively");
f1.close();
f2.close();
f.close();
}
catch(IOException e)
{
System.out.println("Error");
}
}
}