Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default how to solve this ERROR --java.lang.OutOfMemoryError: Java heap space

    I am Trying to read one TEXT file line by line. file size is approx. 7 MB or it contain approx. 35000 line of text.
    i am processing that file and export data into another file.
    mean while after some line i get error like below,

    java.lang.OutOfMemoryError: Java heap space

    After this error process stop.

    my application is in Java Swing and i m using java 1.5 version of SDK and JRE.
    is it a JDK version Problem?

    please can any one give me appropriate solutions for this.
    give me answer please.............

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Rather than read in the whole file, how about streaming in the file and streaming out the processed information. Note that this has nothing to do with Swing and as such I am moving it out of the Swing forum.

    Edit: I see that you've cross-posted this in the Sun forum without informing us, which is not appreciated. The problem is that you're asking unpaid volunteers to help you here, not paid consultants, and most of us mind if we take time away from work/lives/play to try to help someone only to find that we've provided a solution that was already provided in a cross-post hours ago. The proper thing to do is that if you feel you must cross-post, at least provide links in each cross-post to the other, so that folks don't waste time answering something already answered and so that folks can review all discussions that have already occurred.
    Last edited by Fubarable; 08-12-2010 at 01:03 PM.

  3. #3
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Default apologies

    sorry for this cross posting .
    i don't know about this.

  4. #4
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    Well, you could get the text from the text file, then create a conditional:
    Java Code:
    String s = getTextInfo();
    if (s.length > 400){
    s = s.substring(0,400);
    }
    else {
    displayData();
    }
    What this code says:
    If the length of the string is greater then 400, it will trim it, but not delete it from the file. Cheers,
    ~Crikey

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by crikey View Post
    Well, you could get the text from the text file, then create a conditional:
    Java Code:
    String s = getTextInfo();
    if (s.length > 400){
    s = s.substring(0,400);
    }
    else {
    displayData();
    }
    What this code says:
    If the length of the string is greater then 400, it will trim it, but not delete it from the file. Cheers,
    ~Crikey
    That is so silly: what if the processing involves more than just the current line? It renders your example totally useless; it isn't even a clue for the OP.

    kind regards,

    Jos

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default

    And what if the data you have just trimmed is needed for processing, but you've now separated it into two bits that know nothing about each other?

    And anyway, you've already read it in...

Similar Threads

  1. java.lang.OutOfMemoryError: Java heap space
    By paul in forum Advanced Java
    Replies: 11
    Last Post: 06-12-2010, 05:30 PM
  2. Replies: 10
    Last Post: 05-11-2009, 11:56 AM
  3. Replies: 3
    Last Post: 04-22-2009, 08:25 PM
  4. java.lang.OutOfMemoryError: Java heap space
    By vidjogamer in forum New To Java
    Replies: 3
    Last Post: 02-06-2009, 06:52 AM
  5. Replies: 14
    Last Post: 06-12-2008, 08:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •