內部類單例模式,

c3tc3tc3t發表於2013-08-19

package com.zl.util;

import org.dom4j.Document;
import org.dom4j.io.SAXReader;

/**
 * User: c3t
 * Date: 13-8-15
 * Time: 下午3:35
 */
public class XMLUtil {

    private XMLUtil() {

    }

    private static class Help {
        private static Document userDocuemtn;

       static {

            SAXReader saxReader = new SAXReader();
            try {
                userDocuemtn = saxReader.read(XMLUtil.class.getClassLoader().getResourceAsStream("xml/users.xml"));

            } catch (org.dom4j.DocumentException e1) {
                e1.printStackTrace();
            }
        }

    }

    public static final Document getInstance() {
        return Help.userDocuemtn;
    }



}

相關文章