java工程路径


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


这里有一种方法:


把文件放到src路径下


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


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


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

你可能感兴趣的:(java,路径)