gpt4 book ai didi

java - 我如何确保此方法关闭输出流?

转载 作者:行者123 更新时间:2023-11-30 08:03:18 25 4
gpt4 key购买 nike

<分区>

我如何确保此方法关闭 OutputStream 从而不会发生内存泄漏?

public static void store(Properties properties, Class script) throws IOException {
ScriptManifest scriptManifest = (ScriptManifest) script.getAnnotation(ScriptManifest.class);
if (scriptManifest != null) {
String name = scriptManifest.name();
FileOutputStream outputStream = new FileOutputStream(Constants.SCRIPT_PROPERTIES_DIR + File.separator + name + ".properties");
properties.store(outputStream, "");
outputStream.close();
} else {
throw new RuntimeException("Script " + script.getName() + " does not have a ScriptManifest.");
}
}

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