|
|
@ -101,16 +101,18 @@ public class ResourceLeaks {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void twoResourcesHeliosFix() throws IOException {
|
|
|
|
public static void twoResourcesHeliosFix() throws IOException {
|
|
|
|
FileInputStream fis = new FileInputStream(new File("whatever.txt"));
|
|
|
|
FileInputStream fis = null;
|
|
|
|
|
|
|
|
FileOutputStream fos = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
FileOutputStream fos = new FileOutputStream(new File("everwhat.txt"));
|
|
|
|
fis = new FileInputStream(new File("whatever.txt"));
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
fos = new FileOutputStream(new File("everwhat.txt"));
|
|
|
|
fos.write(fis.read());
|
|
|
|
fos.write(fis.read());
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
fos.close();
|
|
|
|
if (fos != null) fos.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
fis.close();
|
|
|
|
if (fis != null) fis.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -870,4 +872,12 @@ public class ResourceLeaks {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int tryWithResource() {
|
|
|
|
|
|
|
|
try (FileInputStream inputStream = new FileInputStream("paf.txt")) {
|
|
|
|
|
|
|
|
return inputStream.read();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|