RAII in Java… is resource disposal always so ugly?
问题 I just played with Java file system API, and came down with the following function, used to copy binary files. The original source came from the Web, but I added try/catch/finally clauses to be sure that, should something wrong happen, the Buffer Streams would be closed (and thus, my OS ressources freed) before quiting the function. I trimmed down the function to show the pattern: public static void copyFile(FileOutputStream oDStream, FileInputStream oSStream) throw etc... {