javase和javaee中获取文件路径的方法总结,javasejavaee
分享于 点击 31474 次 点评:191
javase和javaee中获取文件路径的方法总结,javasejavaee
1. javase中
//获取src路径的一种方式
String srcPath = this.getClass().getClassLoader().getResource("").getPath();//获取src路径的另一种方式
String srcPath2 = InJavaSe.class.getClassLoader().getResource("").getPath();
//获取路径的另一种方式
String srcPath3 = this.getClass().getResource("/").getPath();
//获取当前类路径<包含package路径>
String classPath = this.getClass().getResource("").getPath();
2. javaee中
this.getServletContext().getRealPath("c.txt")
相关文章
- 暂无相关文章
用户点评