import java.io.*;
import java.util.HashSet;
public class FileOperation
{
public static void main(String[] args) throws IOException
{
PrintWriter pw = new PrintWriter("D://output.txt");
BufferedReader br = new BufferedReader(new FileReader("D://input.txt"));
String line = br.readLine();
// set store unique values
HashSet<String> hs = new HashSet<String>();
// loop for each line of input.txt
while(line != null)
{
// write only if not
// present in hashset
if(hs.add(line))
pw.println(line);
line = br.readLine();
}
pw.flush();
// closing resources
br.close();
pw.close();
System.out.println("File operation performed successfully");
}
}
Output:-
No comments:
Post a Comment