Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
HowToKBClustering/src/utils/FileUtils.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
35 lines (30 sloc)
984 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utils; | |
import java.io.BufferedReader; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.HashSet; | |
import java.util.Set; | |
public class FileUtils { | |
public static Set<String> readFileAsSet(String filePath, boolean toLowerCase, boolean trim) { | |
String temp = ""; | |
HashSet<String> lines = new HashSet<String>(); | |
try { | |
BufferedReader in = new BufferedReader(new FileReader(filePath)); | |
while ((temp = in.readLine()) != null) { | |
if (temp.length() > 0) { | |
String UTF8Str = new String(temp.getBytes(), "UTF-8"); | |
if (trim) | |
UTF8Str = UTF8Str.trim(); | |
lines.add(toLowerCase ? UTF8Str.toLowerCase() : UTF8Str); | |
} | |
} | |
in.close(); | |
} catch (FileNotFoundException e) { | |
System.out.println("File not found, in reading file as list: " + e.getMessage()); | |
} catch (IOException e) { | |
System.out.println("IOException in reading file as list: " + e.getMessage()); | |
} | |
return lines; | |
} | |
} |