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 spaceJava 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 spacejava.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 Beginnersjava 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 memoryelasticsearch
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 Beginnersjava 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-inImage 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 memoryheap memory how long is the object stored in
heap memory persist
HEAP tableHEAP 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
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-sortvisualization 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 memoryheap and stack memory hi
i am jane
pls explain the
difference between
heap memory and stack memory with example programs
heap and stack memoryheap 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 '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
heap sort in javaheap 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 languageheap 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
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 complexitytime 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 dockerHow 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 JavaHeap 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
Controlling Java Heap Size Memory AllocationControlling
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 spacepython 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 spacepython 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 javaxmlname
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 PDFWhite
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 '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 '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