【初心者】Java質問・相談スレッド57【大歓迎】
レス数が950を超えています。1000を超えると書き込みができなくなります。
0970デフォルトの名無しさん
NGNG完璧にやるなら下のようになる。ただし日常的にここまでやる奴はキチガイ。
原発のシステムならいいかもね。
>>967の方針でも、最悪GC時にfinalize()が走ってリソースのclose()は実行される。
FileOutputStream fos = null;
OutputStreamWriter osw = null;
BufferedWriter bw = null;
PrintWriter pw = null;
try {
try {
pw = new PrintWriter(bw = new BufferedWriter(osw = new OutputStreamWriter(fos = new FileOutputStream(filename), "Windows-31J")));
pw.println("Hello, World!");
} finally {
if (pw != null) {
pw.close();
} else if (bw != null) {
bw.close();
} else if (osw != null) {
osw.close();
} else if (fos != null) {
fos.close();
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
レス数が950を超えています。1000を超えると書き込みができなくなります。