在网上看到了这样的一段代码,我想以后对自己会有用,也想和大家分享一下!

 1 /**
2 * 获得项目所在路径<br>
3 * @return String<br>
4 */
5 public static String getPath()
6 {
7 URL url = UtilTools.class.getResource("");
8 File file = new File(url.getFile());
9 String path = file.getParent();
10 while (-1 != path.lastIndexOf("bin") || -1 != path.lastIndexOf(".jar"))
11 {
12 file = new File(path);
13 path = file.getParent();
14 }
15 if (path.startsWith("file"))
16 {
17 path = path.replaceAll("file:", "");
18 }
19 path = path + File.separator+"JmailConfig.xml"
20 return path;
21 }



相关文章:

  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-01-28
  • 2021-11-02
  • 2022-02-07
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2021-12-19
  • 2021-06-02
  • 2021-11-19
  • 2022-01-07
相关资源
相似解决方案