Posted By

hyderai on 10/28/11


Tagged


Versions (?)

access data in a jar


 / Published in: Java
 

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

  1. // example code of access data using getResource()
  2. public static File getDefalutPath() {
  3. if(defalutPath == null) {
  4. String defPath = System.getProperty("mmseg.dic.path");
  5. log.info("look up in mmseg.dic.path="+defPath);
  6. if(defPath == null) {
  7. URL url = Dictionary.class.getClassLoader().getResource("data");
  8. if(url != null) {
  9. defPath = url.getFile();
  10. log.info("look up in classpath="+defPath);
  11. } else {
  12. defPath = System.getProperty("user.dir")+"/data";
  13. log.info("look up in user.dir="+defPath);
  14. }
  15.  
  16. }
  17.  
  18. defalutPath = new File(defPath);
  19. if(!defalutPath.exists()) {
  20. log.warning("defalut dic path="+defalutPath+" not exist");
  21. }
  22. }
  23. return defalutPath;
  24. }

Report this snippet  

You need to login to post a comment.