While working on a school project, I wrote the following code:
FileOutputStream fos;
ObjectOutputStream oos;
try {
fos = new FileOutputStream(file);
Unfortunately there is no language level support. But there are lot of libraries out there that makes this simple. Check commons-io library. Or modern google-guava @ http://guava-libraries.googlecode.com/svn/trunk/javadoc/index.html
You're doing it right. It bothers the crap out of me too. You should initialize those streams to null explicitly - it's common convention. All you can do is join the club and want for using
.