Ensure Proper Closure of FileReader When Loading Models
Closed this issue · 0 comments
leewyatt commented
Frank has suggested that we should modify the way we load all of our models to properly close the FileReader resources. This can be achieved by using a try-with-resources block to handle the FileReader, ensuring that it is correctly closed after usage. This change will potentially affect every place where FileReader is used in our codebase.
// load documentation
File documentationFile = new File(getRepositoryDirectory(), "documentation/documentation.json");
List<Documentation> documentation = gson.fromJson(new FileReader(documentationFile, StandardCharsets.UTF_8), new TypeToken<List<Documentation>>() {
}.getType());
File learnJavaFXFile = new File(getRepositoryDirectory(), "learn/javafx/learn.json");
List<LearnJavaFX> learnJavaFX = gson.fromJson(new FileReader(learnJavaFXFile, StandardCharsets.UTF_8), new TypeToken<List<LearnJavaFX>>() {
}.getType());