将文件放到src中,编译後自动到classes目录,然后通过下面的方法就能得到绝对路径了。 前半部分为了防止目录中存在空格的现象。 File f = new File(java.net.URLDecoder.decode(this.getClass().getResource("/").getPath()) + filePath);
将文件放到src中,编译後自动到classes目录,然后通过下面的方法就能得到绝对路径了。前半部分为了防止目录中存在空格的现象。File f = new File(java.net.URLDecoder.decode(this.getClass().getResource("/").getPath()) + filePath);