I have around 100 files in a folder. And I am trying to read all those files one by one. Each file will have data like this and each line resembles an user id.
960904056
6624084
1096552020
750160020
1776024
211592064
1044872088
166720020
1098616092
551384052
113184096
136704072
So I need to read that file line by line and then store each user id in a LinkedHashSet. I am able to read all the files from a particular folder with the below code. But with the below java code that I wrote, I am not sure how to read those files line by line and then store each user id in a LinkedHashSet?
public static void main(String args[]) {
File folder = new File("C:\\userids-20130501");
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
File file = listOfFiles[i];
if (file.isFile() && file.getName().endsWith(".txt")) {
try {
String content = FileUtils.readFileToString(file);
System.out.println(content);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Any help will be appreciated on this? And any better way to do the same process?