我用的是public Document read(String fileName) throws MalformedURLException, DocumentException
{ SAXReader reader = new SAXReader(); Document document = null;
try {
document = reader.read(new FileInputStream(fileName));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} return document; }
这样得到document内存就溢出了,我对dom4jAPI不熟悉,是个新手,请用过dom4j的大侠们,指点迷津,最好是有代码传上,只要能读成功30M的文件,我给100分,十分感谢
{ SAXReader reader = new SAXReader(); Document document = null;
try {
document = reader.read(new FileInputStream(fileName));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} return document; }
这样得到document内存就溢出了,我对dom4jAPI不熟悉,是个新手,请用过dom4j的大侠们,指点迷津,最好是有代码传上,只要能读成功30M的文件,我给100分,十分感谢
具体的设置细节,百度一下,你就知道。
java -Xms64m -Xmx256m test
其中Xms64m表示初始堆为64M,Xmx256m表示最大堆为256M
java -Xms64m -Xmx256m test
同意zangxueyou的留言,DOM4j,SAX,JDOM等有不同的使用范围,Google一下会得到比较详细的解释.
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());
}
}
}