Java - class.getResource 返回 null [英] Java - class.getResource returns null

查看:37
本文介绍了Java - class.getResource 返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下内容来获取此特定文件的 URL,但它返回 null.有没有人对这个问题或替代方法有任何建议?

I am using the following to get the URL of this particular file, but it returns null. Does anyone have any suggestions as to the problem or an alternate way to do this?

URL url = ExchangeInterceptor.class.getResource("GeoIP.dat");

推荐答案

对于那些使用 Intellij Idea 的人:检查 Settings >构建、执行、部署 >编译器资源模式.

For those who use Intellij Idea: check for Settings > Build, Execution, Deployment > Compiler > Resource patterns.

该设置包含应解释为资源的所有扩展.如果扩展不符合此处的任何模式,则 class.getResource 将为使用此扩展的资源返回 null.

The setting contains all extensions that should be interpreted as resources. If an extension does not comply to any pattern here, class.getResource will return null for resources using this extension.

这篇关于Java - class.getResource 返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆