Android Text File Content Remove removeRepeat(String filePath)

Here you can find the source of removeRepeat(String filePath)

Description

remove Repeat

License

Open Source License

Declaration

public static void removeRepeat(String filePath) throws IOException 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

public class Main {

    public static void removeRepeat(String filePath) throws IOException {
        Set<String> set = new HashSet<String>();
        File file = new File(filePath);
        BufferedWriter bw;//from   w w w . ja v a  2 s  . c o  m
        BufferedReader br;
        if (!file.exists())
            return;
        br = new BufferedReader(new FileReader(file));
        while (br.ready()) {
            set.add(br.readLine());
        }
        br.close();
        bw = new BufferedWriter(new FileWriter(file));
        for (String str : set) {
            bw.write(str);
            bw.newLine();
        }
        bw.close();
    }
}