Here you can find the source of readFileToSet(String filePath, String fileEncoding)
public static Set<String> readFileToSet(String filePath, String fileEncoding)
//package com.java2s; //License from project: Open Source License import java.io.*; import java.util.*; public class Main { public static Set<String> readFileToSet(String filePath, String fileEncoding) { if (fileEncoding == null) { fileEncoding = "utf-8"; }/* w w w. j av a 2 s.co m*/ File file = new File(filePath); BufferedReader br = null; String line = null; Set<String> lineSet = new HashSet<String>(); try { br = new BufferedReader(new InputStreamReader( new FileInputStream(file), fileEncoding)); while ((line = br.readLine()) != null) { lineSet.add(line); } return lineSet; } catch (Exception e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; } }