This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
What do you mean by "but it fails...because the length of the file is too big"? Does it die and do nothing? Do you get an error message and if so, what - EXACTLY - does it say? Does it do something else, and if so, what?
How do you know that is it failing because the file is too big?
You need to tell the details if you want any kind of reasonable help.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors