File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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="" target="_blank" rel="nofollow"></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:
subject: Scanner Question (Line Problem)
It's not a secret anymore!