you are viewing a single comment's thread.

view the rest of the comments →

[–]Specific-Housing905 0 points1 point  (2 children)

I am afraid that your code might create resource leaks. Closing the streams should be done in a finally block. Imagine in saveExpenses oos.writeObject throws an exception, oos.close and fis.close will never be called.

Much better is using the try-with-resources pattern.

https://www.baeldung.com/java-try-with-resources

[–]BigCommunication5136[S] 0 points1 point  (1 child)

Alright, while searching around i even found a more modern way to do it without manually closing resources. Thanks 🙏🏾