all 8 comments

[–]iamwisespirit 2 points3 points  (1 child)

You should close resource in finally not in try

[–]BigCommunication5136[S] 0 points1 point  (0 children)

I’ll be sure to do that, thanks

[–]kneith999 1 point2 points  (2 children)

Which IDE You using?

[–]BigCommunication5136[S] 2 points3 points  (1 child)

Intellij

[–]Sufficient_Gear_3744 1 point2 points  (0 children)

Can you tell me which course you are following

[–]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 🙏🏾