java - 为什么在评估调试对象时新的 FileInputStream 返回 null
问题描述
我有这个代码:
InputStream is = new FileInputStream(new FileURL(fileName));
properties.load(is);
我有这个异常: java.lang.NullPointerException: inStream parameter is null
在调试中一步一步走,我看到我的“is”变量为空。但是当我评估(想法中的ctrl + u)时
new FileInputStream(new FileURL(fileName));
我得到了分配给引用属性文件的普通 FileInputStream 对象。请帮忙。
解决方案
你可以这样做:
try
{
File file = new File( fileName ) ;
if (!file.exists())
return ;
FileInputStream in = new FileInputStream( file ) ;
try
{
props.load( in ) ;
}
finally
{
in.close() ;
}
}
catch (Exception exc)
{
if (debug)
System.out.println( "ORB properties file " + fileName +
" not found: " + exc) ;
}
推荐阅读
- dialogflow-es - 如何区分 google home 设备与其他设备
- ruby-on-rails - Rails 阻止特定路线上的 before_action
- java - 如何正确查询服务器信息?
- c++ - 从 Ignite 中读取 Cassandra 的 Blob
- ios - 领域添加不会插入所有对象
- python - Pyqtgraph 设置标签样式
- html - 使用 htm2canvas 获取图像 url 的值
- python - 我在 python 中遇到了 JSON 的问题
- r - 在直方图中为 xaxis 设置限制,包括 0 值
- linux - vbscript 中的 Sendkeys 正在截断在腻子终端中传递的键