Return to Snippet

Revision: 52648
at October 28, 2011 16:22 by hyderai


Updated Code
// example code of access data using getResource()
     public static File getDefalutPath() {
          if(defalutPath == null) {
               String defPath = System.getProperty("mmseg.dic.path");
               log.info("look up in mmseg.dic.path="+defPath);
               if(defPath == null) {
                    URL url = Dictionary.class.getClassLoader().getResource("data");
                    if(url != null) {
                         defPath = url.getFile();
                         log.info("look up in classpath="+defPath);
                    } else {
                         defPath = System.getProperty("user.dir")+"/data";
                         log.info("look up in user.dir="+defPath);
                    }
                   
               }
              
               defalutPath = new File(defPath);
               if(!defalutPath.exists()) {
                    log.warning("defalut dic path="+defalutPath+" not exist");
               }
          }
          return defalutPath;
     }

Revision: 52647
at October 28, 2011 16:22 by hyderai


Initial Code
# example code of access data using getResource()
     public static File getDefalutPath() {
          if(defalutPath == null) {
               String defPath = System.getProperty("mmseg.dic.path");
               log.info("look up in mmseg.dic.path="+defPath);
               if(defPath == null) {
                    URL url = Dictionary.class.getClassLoader().getResource("data");
                    if(url != null) {
                         defPath = url.getFile();
                         log.info("look up in classpath="+defPath);
                    } else {
                         defPath = System.getProperty("user.dir")+"/data";
                         log.info("look up in user.dir="+defPath);
                    }
                   
               }
              
               defalutPath = new File(defPath);
               if(!defalutPath.exists()) {
                    log.warning("defalut dic path="+defalutPath+" not exist");
               }
          }
          return defalutPath;
     }

Initial URL
http://code.google.com/p/mmseg4j/

Initial Description


Initial Title
access data in a jar

Initial Tags


Initial Language
Java