500分求解dom4j装载30M左右XML文件
内存溢出,分不够我开号给
代码如下,我是用的sax为什么也会内存溢出?是不是哪里内存没释放,请高手帮忙看看
import java.io.*;
import
java.net.MalformedURLException;
import java.util.Iterator;
import java.util.List;
import org.dom4j.*;
import org.dom4j.io.SAXReader;
public class ReadAndInsert {
public static void main(String args[])
{
SAXReader sax = new SAXReader();
sax.addHandler( "/DATA/user01 ", new UserHandler());
try {
sax.read(new File( "c:/exp/friend.xml "));
} catch (DocumentException e) {
e.printStackTrace();
}
}
public static class UserHandler implements ElementHandler
{
Element e = null;
public void onStart(ElementPath path) {
e = path.getCurrent();
path.addHandler( "USERID ", new NameHandler());
path.addHandler( "FNAME ", new NameHandler());
path.addHandler( "ORGID ", new NameHandler());
path.addHandler( "ORGNAME ", new NameHandler());
path.addHandler( "FROMORG ", new NameHandler());
System.out.println(path.getPath()+ "*************************** ");
//System.out.println(e.getName()+ ": "+e.getText());
}
public void onEnd(ElementPath path) {
path.removeHandler( "USERID ");
path.removeHandler( "FNAME ");
path.removeHandler( "ORGID ");
path.removeHandler( "ORGNAME ");
path.removeHandler( "FROMORG ");
}
}
public static class NameHandler implements ElementHandler
{
Element e = null;
public void onStart(ElementPath path) {
System.out.println(path.getPath());
}
public void onEnd(ElementPath path) {
e = path.getCurrent();
System.out.println(e.getName()+ ": "+e.getText());
}
}
}
------解决方案--------------------调调jvm的虚拟内存试试
------解决方案--------------------默认是 <=512M吧?不太清楚了。
程序本身好像没什么问题