Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

managing big data in string

 
Nischal Topno
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Nischal
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use a java.io.BufferedReader 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic