out of memory error when writing large file
I have the piece of code below which works fine for writing small files, but when it encounters much larger files (>80M), the jvm throws an out of memory error.
I believe it has something to do with the Stream classes. If I were to replace my PrintStream reference with the System.out object (which is commented out below), then it runs fine.
Anyone else encountered this before?
print = new PrintStream(new FileOutputStream(new File(a_persistDir, getCacheFilename()),
false));
//print = System.out;
for(Iterator strings = m_lookupTable.keySet().iterator(); strings.hasNext(); ) {
StringBuffer sb = new StringBuffer();
String string = (String) strings.next();
String id = string;
sb.append(string).append(KEY_VALUE_SEPARATOR);
Collection ids = (Collection) m_lookupTable.get(id);
for(Iterator idsIter = ids.iterator(); idsIter.hasNext();) {
IBlockingResult blockingResult = (IBlockingResult) idsIter.next();
sb.append(blockingResult.getId()).append(VALUE_SEPARATOR);
}
print.println(sb.toString());
print.flush();
}
} catch (IOException e) {
...
} finally {
if( print != null )
print.close();
}

