using java.lang.OutOfMemoryError: Java heap space

using java.lang.OutOfMemoryError: Java heap space

i wrote a program that reads and writes multiple files and combines them and writes them as one single file in as CVS format(bin.txt). After the program is done then another class reads the new file and removes extra delimiter(,) that the first file had at the end for some reason. the problem comes in when i have large file > 40mb and my program has this error "using java.lang.OutOfMemoryError: Java heap space " when the second class tries and reads and write the (bin.txt). here is my code

:::::::::main class:::::: package elite.tech.com;

/*********** * program Cvs * @author Alain ndayishimiye * @version 1 * @since 2012 **********/ import java.io.File; import java.io.IOException;

public class testing{ static String outpath = "C:\Users\ndayala\bin\bin.txt"; public static void main(String[]args) throws IOException, InterruptedException{ Firstread t1; Secondread t2; t1 = new Firstread(); t2 = new Secondread();

    t1.runn1();
    System.out.println("done about to start 2");
    File file = new File(outpath);
    long filesize = file.length();
    long filesizeInKB = filesize / 1024;
    System.out.println("The output file is of size : " + filesizeInKB + " KB");

    if(t1.isAlive()==false){


        System.out.println("second thread is about to start");
        Thread.sleep(10000);
        System.out.println("starting the second");
        t2.runn2();
    }
}

}

::::::::::::::first class:::::::::::::::::::::::::::::::::::::;;; package elite.tech.com; /*********** * program Cvs * @author Alain ndayishimiye * @version 1 * @since 2012 **********/ import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter;

public class Firstread extends Thread{ static String inpath = "C:\Users\ndayala\asc"; static String outpath = "C:\Users\ndayala\bin\bin.txt"; public void runn1() throws IOException{

    PrintWriter pw = new PrintWriter(new FileOutputStream(outpath ));// write to the outpath dir

    File file = new File(inpath);//files from the inpath
    File[] files = file.listFiles();//listFiles all file in inpath dir


    for (int i = 0; i < files.length; i++) {
        System.out.println("Processing " + files[i].getPath() + "... ");
        BufferedReader br = new BufferedReader(new FileReader(files[i].getPath()));
        String line = br.readLine();

        while (line != null) {
            line = line.replace(" ","" ); 
            line = line.replace("mSOriginatingSMSinMSC","" );  
            line = line.replace("GSMPLMNCallDataRecord","" ); 
            line = line.replace("tAC","" ); 
            line = line.replace("callIdentificationNumber","" ); 
            line = line.replace("recordSequenceNumber","" );  
            line = line.replace("typeOfCallingSubscriber","" ); 
            line = line.replace("callingPartyNumber","" ); 
            line = line.replace("callingSubscriberIMSI","" );  
            line = line.replace("callingSubscriberIMEI","" ); 
            line = line.replace("dateForStartofCharge","" ); 
            line = line.replace("->0|0|6","" );

            System.out.println("writting:........"+files[i]);
            char delim =',';
            pw.print(line+delim);
            line = br.readLine();
        }
        br.close();
    }
    pw.close();
    System.out.println("your file have been concatenaded into one file under directory "+outpath);
    //convert(outpath);
}

}

::::::::::::second class::::::::::::::::::::::::::::::::::::::::::

package elite.tech.com; /*********** * program Cvs * @author Alain ndayishimiye * @version 1 * @since 2012 **********/ import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter;

public class Secondread extends Thread{ static String inpat = "C:\Users\ndayala\bin",outpat = "C:\Users\ndayala\bin.txt"; public void runn2() throws IOException{ PrintWriter pw = new PrintWriter(new FileOutputStream(outpat ));// write to the outpath dir

    File file = new File(inpat);//files from the inpath
    File[] files = file.listFiles();//listFiles all file in inpath dir


    for (int i = 0; i < files.length; i++) {
        System.out.println("Processing " + files[i].getPath() + "... ");
        BufferedReader br = new BufferedReader(new FileReader(files[i].getPath()));
        String line = br.readLine();

        while (line != null) {
            line = line.replace(",,","" ); 


            System.out.println("writting:........"+files[i]);
            pw.print(line);
            line = br.readLine();
        }
        br.close();
    }
    pw.close();
    System.out.println("your file has been created in:        "+outpat);
    //convert(outpath);
}

}

View Answers









Related Tutorials/Questions & Answers:
using java.lang.OutOfMemoryError: Java heap space
and my program has this error "using java.lang.OutOfMemoryError: Java heap space...using java.lang.OutOfMemoryError: Java heap space  i wrote a program that reads and writes multiple files and combines them and writes them as one
Java heap space
Java heap space  I am using MyEclipse 8.6 for my web based project. The command may be... Ex: java -Xms32m -Xmx128m How can I increase java heap... options available to change Heap Size. 1 -Xms<size> set initial Java
Advertisements
java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space  Hi, How to resolve java.lang.OutOfMemoryError: Java heap space error. This error is coming while... java.lang.OutOfMemoryError: Java heap space where there is no more space available
java.lang.OutOfMemoryError: Java heap space
" java.lang.OutOfMemoryError: Java heap space How to resolve this issue? Thanks   Hi... your program. Check the thread Java heap space and java.lang.OutOfMemoryError: Java heap space. Thanks
java heap space & netbeans - Java Beginners
java heap space & netbeans  Java heap space". I'm using netbeans 5.1.1 and jdk1.5.0_07 version.. can any body say how can i know the amount of java heap space while i run...java heap space & netbeans Hey,all!! I've got a problem
elasticsearch java heap space out of memory
elasticsearch java heap space out of memory  Hi, How to set heap size in elasticsearch to overcome java heap space out of memory? Thanks   Hi, Set following value in environment variables: export ES_HEAP_SIZE=10g
java heap space bpbroble - Java Beginners
java heap space bpbroble  In my code i use JXmapViewier to show location on map but but after some time (When code is running )It give me exception that Java heap space problem how to solve that one or why this problem occurs
Image Slide Show using 'Space gallery' plug-in
Image Slide Show using  'Space gallery' plug-in In this tutorial , we will create a slide show using 'Space gallery' plug-in .In this example , two tabs are given. in one tab 'Space gallery' slide show
Heap Sort in Java
Heap Sort in Java      ... are going to sort integer values of an array using heap sort. There are two types... minimum root than his child. We can sort the array values using heap sorting
heap memory
heap memory  how long is the object stored in heap memory persist
HEAP table
HEAP table  hiii, What is HEAP table?   hello,ADS_TO_REPLACE_1 This type of table is stored in the memory. Speed of execution of this table is very commendable
Java Heap
Java Heap       The JVM's heap stores all the objects generating by a running Java program. Java uses... if an object is no longer referenced by the program, the heap space it occupies
How to remove the space between a JComponent and its Grid border while using GridBagLayout?
How to remove the space between a JComponent and its Grid border while using GridBagLayout?   Hi, I had try to design a UI using GridBagLayout.I... space between the Label text and the TextBox.Could anyone help me to reduce
heap memory in j2me
heap memory in j2me  how to get j2me heap memory size
ModuleNotFoundError: No module named 'heap'
ModuleNotFoundError: No module named 'heap'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'heap' How to remove the ModuleNotFoundError: No module named 'heap' error
visualization Max-Heap-sort
visualization Max-Heap-sort  To Whom It May Concern, Would you please give the source code of applet Max-heap sort? I want to see the visualization of Max-Heap sort. Best Regards, saeideh
heap and stack memory
heap and stack memory   hi i am jane pls explain the difference between heap memory and stack memory with example programs
hw to increazse heap size in my eclipse
hw to increazse heap size in my eclipse   how can i increase heap size using my eclipse
heap and stack memory
heap and stack memory   hi i am jane pls explain the difference between heap memory and stack memory   STACK memory... after v came out from the program]. While HEAP memory is referred as permanent
ModuleNotFoundError: No module named 'tap-heap'
ModuleNotFoundError: No module named 'tap-heap'  Hi, My Python...-heap' How to remove the ModuleNotFoundError: No module named 'tap-heap... to install padas library. You can install tap-heap python with following
ModuleNotFoundError: No module named 'tap-heap'
ModuleNotFoundError: No module named 'tap-heap'  Hi, My Python...-heap' How to remove the ModuleNotFoundError: No module named 'tap-heap... to install padas library. You can install tap-heap python with following
ModuleNotFoundError: No module named 'binary-heap'
ModuleNotFoundError: No module named 'binary-heap'  Hi, My Python... 'binary-heap' How to remove the ModuleNotFoundError: No module named 'binary-heap' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'd-heap'
ModuleNotFoundError: No module named 'd-heap'  Hi, My Python...-heap' How to remove the ModuleNotFoundError: No module named 'd-heap'... to install padas library. You can install d-heap python with following command
ModuleNotFoundError: No module named 'django-heap'
ModuleNotFoundError: No module named 'django-heap'  Hi, My Python... 'django-heap' How to remove the ModuleNotFoundError: No module named 'django-heap' error? Thanks   Hi, In your python environment
heap sort in java
heap sort in java  plz modify this program so that it can take input as integers and string both..... public class heap_Sort{ public static void...("\n Heap Sort\n---------------\n"); System.out.println("\n Unsorted Array\n\n
heap and stack in general programming language
heap and stack in general programming language  what's the difference between heap and stack ?   Hi Friend, Differences:ADS_TO_REPLACE_1 1)Stack is referred as temporary memory while Heap is referred as permanent
Remove Extra Space At End
Remove Extra Space At End  Remove Extra Space At End
diskfreespace php, Find free disk space from PHP program
will shows how you can find the free disk space from your php program...(directory_path) gives the free space present on the disk in bytesADS_TO_REPLACE_2 works same as the function disk_free_space() works in php4 and php5 Code
time and space complexity
time and space complexity  sort the data structures according to efficient time and space utilisation
ModuleNotFoundError: No module named 'space'
ModuleNotFoundError: No module named 'space'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'space' How to remove the ModuleNotFoundError: No module named 'space'
How to set heap memory in cassandra on docker
How to set heap memory in cassandra on docker  I am trying to run cassandra on docker and its throwing error asking to set the heap memory. It is throwing error and asking to set following varibales: HEAP_NEWSIZE=128M MAX_HEAP
Heap Sort in Java
Heap Sort in Java is used to sort integer values of an array. Like quicksort... values in heap is not 0. Example of Heap Sort in Java: public class eap...:\array\sorting>java heap_Sort Heap Sort --------------- Unsorted Array 1 3
ModuleNotFoundError: No module named 'fibonacci-heap-mod'
ModuleNotFoundError: No module named 'fibonacci-heap-mod'  Hi, My... named 'fibonacci-heap-mod' How to remove the ModuleNotFoundError: No module named 'fibonacci-heap-mod' error? Thanks   Hi, In your
Controlling Java Heap Size Memory Allocation
Controlling Java Heap Size Memory Allocation  Hi, Tell me about Controlling Java Heap Size Memory Allocation? I have to run java program from console and allocate 2GB of RAM to Java Heap Size. Thanks   Hi, You can
Program to Ignore Space and Enter ?!
Program to Ignore Space and Enter ?!  Hi, dear friend i wont to write program to enter many statements, if i use Space and Enter in the Run Time must be delete the space and ignore the Enter ..for example if i entered
Java get Heap Size
Java get Heap Size       In this section, we are going to illustrates you how to obtain the heap size. The heap is the area in the memory used for memory storage during
python replace newline with space
python replace newline with space  Hi, I want to replace newline character \n With space in python. How to replace newline with space in python? Thanks   Hi, Its easy in python. You can use the replace method
python replace newline with space
python replace newline with space  Hi, I want to replace newline character \n With space in python. How to replace newline with space in python? Thanks   Hi, Its easy in python. You can use the replace method
xmlname space in java
xmlname space in java  hi i want to write code like , i used setAttribute method for this. but its showing ERROR: 'Namespace for prefix.... please help me to write this syntax in java
space around/between my images
space around/between my images  How do I eliminate the space around/between my images
how to space images in html code
how to space images in html code  how to space images in html code
White Space encoding problem in PDF
White Space encoding problem in PDF  I am reading PDF version 1.3 using iText. Things are fine but with one problem that is I am not able to get whitespace. Is there any problem in whitespace encoding in PDF version 1.3
ModuleNotFoundError: No module named 'assoc_space'
ModuleNotFoundError: No module named 'assoc_space'  Hi, My Python... 'assoc_space' How to remove the ModuleNotFoundError: No module named 'assoc_space' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'coverage-space'
ModuleNotFoundError: No module named 'coverage-space'  Hi, My... named 'coverage-space' How to remove the ModuleNotFoundError: No module named 'coverage-space' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'py_space'
ModuleNotFoundError: No module named 'py_space'  Hi, My Python..._space' How to remove the ModuleNotFoundError: No module named 'py_space... to install padas library. You can install py_space python with following
ModuleNotFoundError: No module named 'python-space'
ModuleNotFoundError: No module named 'python-space'  Hi, My Python... 'python-space' How to remove the ModuleNotFoundError: No module named 'python-space' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'sample_space'
ModuleNotFoundError: No module named 'sample_space'  Hi, My Python... 'sample_space' How to remove the ModuleNotFoundError: No module named 'sample_space' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'space-aliens'
ModuleNotFoundError: No module named 'space-aliens'  Hi, My Python... 'space-aliens' How to remove the ModuleNotFoundError: No module named 'space-aliens' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'space-api'
ModuleNotFoundError: No module named 'space-api'  Hi, My Python... 'space-api' How to remove the ModuleNotFoundError: No module named 'space... have to install padas library. You can install space-api python with following
ModuleNotFoundError: No module named 'space-bandits'
ModuleNotFoundError: No module named 'space-bandits'  Hi, My... 'space-bandits' How to remove the ModuleNotFoundError: No module named 'space-bandits' error? Thanks   Hi, In your python

Ads