File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes managing big data in string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "managing big data in string" Watch "managing big data in string" New topic

managing big data in string

Nischal Topno
Ranch Hand

Joined: Nov 24, 2001
Posts: 45
how to manage big string data. if i use the String object i run out of memory.

Through the program i'm trying to search for a given word in a given file. The logic i've used is read the file as InputStream and covert the bytes read to String. In this string do and indexOf() of the word i'm searching.

This works fine for small files, but if the file is big it runs out of memory. i am using a P3 555 Mhz with 256 mb RAM and it runs out of memory for a 20 mb file.

Any smart way to achieve the goal?

if i've to manipulate huge chunks of String data what is the way out?

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You could use a to read the file. It has a readLine() method that reads a line at a time into a String variable. You could then search the variable for the word, note whether it is found or not, and then read the next line into the same String variable.

This way, you're only processing one line at a time, and don't need to store the entire file in memory while you're processing it.
[ March 18, 2005: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
I agree. Here's the link:
subject: managing big data in string
It's not a secret anymore!