Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
807603Feb 1 2008 — edited Feb 1 2008I am getting the following error when I am running this program. This program is run on a very large file. What it does is, it takes a record one by one at a time and feeds to a URL and then again takes the value from the URL and then writes it to another file. The file that I am inputing is a very large file(1 million records approx), by the time I reach the end of the it gives me the 'Exception in thread "main" java.lang.OutOfMemoryError: Java heap space' exception. Is there a way I can avoid this?
{
package javaapplication15;
import java.io.*;
import java.net.*;
import java.io.FileOutputStream;
/**
*
* @author hmami001
*/
public class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
FileReader input_file = null;
BufferedReader buff_input1 = null;
BufferedReader buff_input2 = null;
FileWriter osw_output = null;
String line;
String inputline;
String[] input_record;
String[] input2_record;
String lat;
String lon;
URL myurl = null;
try {
input_file = new FileReader("C:/Documents and Settings/hmami001/Desktop/xanadu.txt"); //reads lines from this file
buff_input1 = new BufferedReader(input_file);
osw_output = new FileWriter("C:/Documents and Settings/hmami001/Desktop/test.txt");
while((line=buff_input1.readLine())!=null) {
input_record = line.split("\t");
String zip = input_record[43];
myurl = new URL("http://stree1.cs.fiu.edu:88/street?street="+zip); // feeds the lines to the URL
buff_input2 = new BufferedReader(new InputStreamReader(myurl.openStream()));
inputline = buff_input2.readLine();
input2_record = inputline.split("\t");
lat = input2_record[0];
lon = input2_record[1];
System.out.println("the lat:"+lat);
System.out.println("the lon:"+lon);
osw_output.append(lat+"\t"+lon);
osw_output.append((char)13);
osw_output.append((char)10);
}
osw_output.flush();// writes to the file
osw_output.close();
input_file.close();
} catch(MalformedURLException e) {
System.out.println("IO ERROR!:"+e.getMessage());
} catch(IOException ee) {
System.out.println("I AM IN ERROR!:"+ee.getMessage());
}
}
}
}