0
点赞
收藏
分享

微信扫一扫

java工程路径

逸省 2023-08-08 阅读 66



有时候我们需要用到一些文件,但是用本地路径又不方便,我们想加载到工程中,那么我们怎样才能得到它的路径呢


这里有一种方法:


把文件放到src路径下


在需要使用文件Standardzid.xls的类  AclassName中

String filePath = "classes/Standardzid.xls"; 
URL filePath =AclassName.class.getClassLoader().getResource("Standardzid.xls"); 
File file = new File(filePath.getPath());

这样就可以获取到这个文件了

举报

相关推荐

0 条评论