// 第一种:获取类加载的根路径   D:\IDEAWorkspace\hs-bluetooth-lock\src\applications\bluetooth-api\target\classes
File f = new File(this.getClass().getResource("/").getPath());
System.out.println(f); // 获取当前类的所在工程路径; 如果不加“/” 获取当前类的加载目录 D:\IDEAWorkspace\hs-bluetooth-lock\src\base\target\classes\com\hs\lock\bluetooth\base\utils
File f2 = new File(this.getClass().getResource("").getPath());
System.out.println(f2); // 第二种:获取项目路径 D:\IDEAWorkspace\hs-bluetooth-lock
File directory = new File("");// 参数为空
String courseFile = directory.getCanonicalPath();
System.out.println(courseFile); // 第三种: file:/D:/IDEAWorkspace/hs-bluetooth-lock/src/applications/bluetooth-api/target/classes/
URL xmlpath = this.getClass().getClassLoader().getResource("");
System.out.println(xmlpath); // 第四种: 获取当前工程路径 D:\IDEAWorkspace\hs-bluetooth-lock
System.out.println(System.getProperty("user.dir")); // 第五种: 获取所有的类路径 包括jar包的路径
System.out.println(System.getProperty("java.class.path"));

最新文章

  1. div内容上下居中
  2. Python3基础 random 产生置顶区间的随机整数
  3. 【转】VB中应用DDE
  4. linux centos各种问题解决汇总
  5. MVC去掉传参时的验证:从客户端中检测到有潜在危险的Request.QueryString值
  6. WordPress RokNewsPager插件‘thumb.php’多个安全漏洞
  7. Mediator - 中介者模式
  8. jq判断元素是否显示
  9. php实现仿百度分页
  10. vue版 文件下载
  11. English Conversations You Can Download for Free (Spoken English MP3/Audio Files)
  12. C/S,B/S的应用的区别
  13. Python 基于python实现单例模式
  14. std::shared_ptr 和普通指针的转换
  15. webbrowser获取无ID无Name控件并模拟点击
  16. WPF 从文件加载字体
  17. UVALive 5058 Counting BST 数学
  18. windows mysql默认配置文件
  19. Transform动画初解 in Swift
  20. 关于node npm的一个解决方法

热门文章

  1. MyEclipse 新手使用教程---图文详解
  2. 用gogs轻松搭建个人的git服务器
  3. .NET快速信息化系统开发框架 V3.2->Web版本新增“文件管理中心”集上传、下载、文件共享等一身,非常实用的功能
  4. Python3+Selenium2完整的自动化测试实现之旅(四):Selenium-webdriver操作浏览器、Cookie、鼠标键盘、警示框、设置等待时间、多窗口切换
  5. [Linux] memache打印所有的key
  6. [PHP] defunct僵尸进程
  7. jquery 实现省市二级联动,附带完整的省市json数据 (粘贴即用)
  8. 单元测试与Mockito
  9. 由AbstractQueuedSynchronizer和ReentrantLock来看模版方法模式
  10. Python re 模块