高手帮忙,有答案立即结帖
这段代码为什么输出为0?“menu_zh.xml”文件明明有内容,怎么读不出呀?
import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
public class ItemReader extends DefaultHandler {
private ArrayList <String> arrayList = new java.util.ArrayList <String> ();
private LinkedList items;
private Item tempItem;
private Field tempField;
private static ItemReader handler = new ItemReader();
private ItemReader() {
}
public static ItemReader getInstance() {
return handler;
}
public LinkedList readItem(String fileName) {
try {
items = new LinkedList ();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
reader.setContentHandler(this);
File f = new File(fileName);
if (f.exists()) {
fileName = "file: " + f.getAbsolutePath();
reader.parse(fileName);
}
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
return items;
}
public void startElement(String namespaceURI, String localName,
&n