Skip to content

Commit 325ae69

Browse files
authored
Merge pull request darpanjbora#9 from JD235/javprog
DuplicateLineElimination Prog in JAVA added :)
2 parents af39434 + d9c2df8 commit 325ae69

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.io.*;
2+
class DuplicateElimination
3+
{
4+
public static void main(String[] args) throws Exception
5+
{
6+
System.out.println("Removing Duplicate lines in file");
7+
BufferedReader br1 = new BufferedReader(new FileReader("input.txt"));
8+
PrintWriter pw = new PrintWriter("output.txt");
9+
String line = br1.readLine();
10+
while (line != null)
11+
{
12+
boolean available = false;
13+
BufferedReader br2 = new BufferedReader( new FileReader("output.txt") );
14+
String target = br2.readLine();
15+
while (target != null)
16+
{
17+
if (line.equals(target) )
18+
{
19+
available = true;
20+
break;
21+
}
22+
target = br2.readLine();
23+
}
24+
if (available == false)
25+
{
26+
pw.println(line);
27+
pw.flush();
28+
}
29+
line = br1.readLine();
30+
}
31+
}
32+
}

DuplicateLinesElimination/input.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Hello World..!!
2+
Hello World..!!
3+
Hello World..!!
4+
What's up :)
5+
What's up :)
6+
What's up :)

0 commit comments

Comments
 (0)