Hacker News new | ask | show | jobs
by nie100sowny 1503 days ago
I wonder why in the middle of 2022 people still put pre-2011 and pre-JDK7 snippets. And even try-with-resources example is not all what JDK7 provides, there are better, high-level utilities added which haven't got a proper attention.

Namely, in JDK7 and newer, you can just write: Files.readAllBytes(Path.get("story.txt"))

1 comments

The point of the article was to compare how resource cleanup works in general in different languages. What you show here is a very special case that does not extend to other resources or even other file operations. Still, try-with-resources and AutoClosable is the best what Java has to offer, and it is clearly inferior to Rust/C++ approach (and to some degree also to Go and Zig, but less so).