您的位置:首页 > 编程语言 > Java开发

javase和javaee中获取文件路径的方法总结

2016-04-12 15:31 211 查看
原文地址:http://blog.csdn.net/ranmudaofa/article/details/39505289

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")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: