jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Scanner Question (Line Problem) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Scanner Question (Line Problem)" Watch "Scanner Question (Line Problem)" New topic

Scanner Question (Line Problem)

Rob Mech
Ranch Hand

Joined: Apr 05, 2007
Posts: 56
Hopefully this is a no-brainer for somone. I have some data that I'd prefer to read in with the Scanner class. I have to break up this data and scanner works perfectly for it.

My problem is that the data contains no CRLF (or any other line break character).

For example:


That might be an example line however it's HUGE (2-3 MB files). When I input this into the scanner and just use the ~ as a delimiter it runs out of Heap space.

I'd like to gracefully parse through this preferably using "next".

I've thought about just using a more "low level" read and replacing the ~ with a ~(CRLF) and then re-opening the stream but I'd prefer to make it more efficient.


Rob Mech, SCJP 1.5<br /><a href="http://www.robsprogrammingjunk.com/" target="_blank" rel="nofollow">http://www.robsprogrammingjunk.com/</a>
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Show how you used Scanner with a little code. Running out of heap makes me think you tried to read the whole thing at once somehow.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link: http://aspose.com/file-tools
subject: Scanner Question (Line Problem)
It's not a secret anymore!