Java InputStreamReader Read readFileToSet(String filePath, String fileEncoding)

Here you can find the source of readFileToSet(String filePath, String fileEncoding)

Description

read File To Set

License

Open Source License

Declaration

public static Set<String> readFileToSet(String filePath,
            String fileEncoding) 

Method Source Code

//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;
    }
}

Related

  1. readFileOrResource(String source)
  2. readFiles(String[] files, String encoding)
  3. readFileSB(File f)
  4. readFileToLines(File file)
  5. readFileToList(String fileName, String codeing)
  6. readFileUtf8(IFile file)
  7. readFileWithThrow(IFile in)