alain ndayishimiye
using java.lang.OutOfMemoryError: Java heap space
0 Answer(s)      3 years and 3 months ago
Posted in : Java Beginners

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);
}

}

Advertisement
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.lang.OutOfMemoryError: Java heap space
space. You can also increase the Java heap space using following parameters... java.lang.OutOfMemoryError: Java heap space error. This error is coming while...: Java heap space where there is no more space available for the Java program
Advertisements
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
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
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
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
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 table
HEAP table  hiii, What is HEAP table?   hello, 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
heap memory in j2me
heap memory in j2me  how to get j2me heap memory size
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
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 and stack in general programming language
heap and stack in general programming language  what's the difference between heap and stack ?   Hi Friend, Differences: 1)Stack is referred as temporary memory while Heap is referred as permanent memory. 2)In stack
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
Remove Extra Space At End
Remove Extra Space At End  Remove Extra Space At End
Heap Sort in Java
Heap Sort in Java is used to sort integer values of an array. Like quicksort.... Example of Heap Sort in Java: public class eap_Sort{ public static void main...\sorting>Javac heap_Sort.java C:\array\sorting>java heap_Sort Heap Sort
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
time and space complexity
time and space complexity  sort the data structures according to efficient time and space utilisation
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
diskfreespace php, Find free disk space from PHP program
will shows how you can find the free disk space from your php program...) gives the free space present on the disk in bytes works same as the function disk_free_space() works in php4 and php5 Code for freediskspace() Function PHP
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
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
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
how to space images in html code
how to space images in html code  how to space images in html code
space around/between my images
space around/between my images  How do I eliminate the space around/between my images
remove space - Java Beginners
remove space  I want to remove all line in text file using java. i want all text in single line. example. Input file This is text. I want remove all line. Output file This is text
Validaton(Checking Blank space) - Spring
Validaton(Checking Blank space)  Hi i am using java springs .I am having problem in doing validation. I am just checking blank space. This is my controller. I named it salescontroller. package controller; import