File f = new File(this.getClass().getResource(“路径/目录”).toURI()); 只适合于要读取的文件在文件夹中,如果要读取的文件在jar中,就会报错:java.lang.IllegalArgumentException: URI is not hierarchical
原因:jar包中的文件不能通过这种方式读取,因为目录是不透明的
解决方法:
InPutStream in = this.getClass().getResourceAsStream("路径/目录")
List<String> lines = IOUtils.readLines(in, Charsets.toCharset("UTF-8"));