how to read a file, line by line, without load all file on memory
534 views
Skip to first unread message
Augusto Vilarim
unread,
May 16, 2014, 10:40:35 AM5/16/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to bea...@googlegroups.com
Hi Everyone!
First of all, sorry about my poor english.
Well, i´m trying to read and parse a huge file with beanIO, and my concern is about memory allocation. When i do my brenchmark here, i notice that i dont need to load all beans on memory, i just need one single line per validation, there is some way to load one line per loop in memory, to avoid high memory usage?
Thanks a lot!
Paul Rule
unread,
May 26, 2014, 7:01:12 AM5/26/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to bea...@googlegroups.com
BeanIO doesn't need to read the whole file into memory - you just read one 'object'/line at a time.
BeanReader in = factory.createReader("employeeFile", new File("employee.csv"));
Employee employee;
while ((employee = (Employee) in.read()) != null) {
// process the employee...
}
in.close();
The line
employee = (Employee) in.read()
is just reading (streaming) one line at a time AFAIK.
If you read a massive file in this manner, hopefully you wont' see any significant memory usage.