What is the most efficient way (In terms of time) to read a text file into a list of array. File are of size 100 mb to 2 gb. The file contains data in following formatted :
From TO time
a b 13 decc 2009
b c 13 decc 2009
c d 13 decc 2009
f h 13 decc 2009
f g 13 decc 2009
Edit: Following is code for reading file
public List<InputDataBean> readInputData() throws Exception{
List<InputDataBean> dataSet = new ArrayList<InputDataBean>();
FileInputStream fstream = null;
BufferedReader br = null;
try{
fstream = new FileInputStream(filePath);
br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
Set<String> users = new TreeSet<String>();
while ((strLine = br.readLine()) != null) {
InputDataBean data = validateRecord(strLine);
if(data==null)
continue;
dataSet.add(data);
users.add(data.getFromName());
users.add(data.getToName());
}
UserKeys.setUsers(users);
}catch (Exception e){
throw e;
}finally{
try {
if(null!=br)
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return dataSet;
}
After reading file I want to store into array not to database.
If any other better alternative for reading file? Is it good idea to call script from java program and read data using script and store into java array.
P.S.: I really appreciate if anybody can edit or improve tags.