access data in a jar


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.