我在我的应用程序中使用以下java代码:
if (! key_exists('field', $displayData))
{
return;
}
$field = $displayData['field'];
$label = $field->label;
$value = $field->value;
if (! $value)
{
return;
}
$class = $field->render_class;
?>
<dd class="dpfield-entry <?php echo $class;?>">
<span class="dpfield-label"><?php echo htmlentities($label);?>: </span>
<span class="dpfield-value"><?php echo $value;?></span>
</dd>
在EncryptionFactoryBean.java
中protected String encryptContact(Long contactId) {
if (contactId != null) {
EncryptionFactoryBean enbe = new EncryptionFactoryBean(String.valueOf(contactId), "/etc/test/encrypt.properties");
try {
enbe.SetProperties();
return (String) enbe.getObject();
} catch (Exception e) {
return null;
}
}
return null;
}
在运行应用程序时,我收到以下错误 -
javax.servlet.ServletException:java.io.FileNotFoundException: /etc/test/encrypt.properties(打开的文件过多)
无法在应用程序中增加文件限制。有什么方法可以解决这个问题吗?是否可以通过 public void setProperties()
throws Exception {
Assert.notNull(textToEncrypt, "encryption text cannot be null");
encryptionProperties = loadFile(encryptionFile);
super.setProperties();
}
protected Properties loadFile(String filename)
throws IOException {
Properties properties = null;
if (StringUtils.hasText(filename)) {
File file = new File(filename);
if (file.exists()) {
FileInputStream fi = new FileInputStream(file);
properties = new Properties();
properties.load(fi);
fi.close();
}
}
return properties;
}
?
控制台日志错误:
finally
答案 0 :(得分:0)
最有可能在new EncryptionFactoryBean(String, String)
过程中你有类似
Properties props = new Properties();
Reader inStream = new FileReader("/etc/test/encrypt.properties");
props.load(inStream);
正如Properties.load(Reader) / Properties.load(InputStream)提到的Javdoc
此方法返回后,指定的流仍保持打开状态。
您需要自己关闭流。例如:
Properties props = new Properties();
try (Reader inStream = new FileReader("/etc/test/encrypt.properties")) {
props.load(inStream);
}