这是我之前重复的问题Why is NetBeans saying "incompatible thrown types IOException in method reference"? [duplicate]的后续跟进。 为什么NetBeans在捕获IOException时告诉我"unreported exception IOException; must be caught or declared to be thrown"
?
/**
* Either extracts or returns the pre-extracted language file for the given locale
*
* @param locale the locale
* @return
* @throws IOException
*/
public static InputStream getLanguageFile(Locale locale) throws IOException
{
File extracted = SaveConstants.inventSaveFileFor(Main.GAME_NAME, locale.toLanguageTag() + ".lang");
if (!extracted.exists())
{
InputStream in = Resources.getLanguageStream(locale);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
extracted.getParentFile().mkdirs();
try
{
extracted.createNewFile();
Writer writer = new FileWriter(extracted);
reader
.lines()
.forEach((str) -> writer.write(str));
}
catch (IOException ex)
{
Logger.getLogger(Lang.class.getName()).log(Level.SEVERE, "Cannot extract language file for " + locale + ". Loading directly to map", ex);
return in;
}
}
else
return new FileInputStream(extracted);
}
注意:我知道由于缺少回报而无法编译,但我希望在转到返回
之前解决这个问题