gpt4 book ai didi

java - 强制 FileNotFoundException

转载 作者:行者123 更新时间:2023-11-28 20:17:13 27 4
gpt4 key购买 nike

我正在为一段代码编写测试,其中包含我试图涵盖的 IOException 捕获。 try/catch 看起来像这样:

try {
oos = new ObjectOutputStream(new FileOutputStream(cacheFileName));
} catch (IOException e) {
LOGGER.error("Bad news!", e);
} finally {

最简单的方法似乎是让 FileOutputStream 抛出 FileNotFoundException,但也许我的处理方式完全错误。

有人有什么建议吗?

最佳答案

您可以将 cacheFileName 设置为无效名称或您知道不存在的名称。

关于java - 强制 FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/604449/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com