1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| final Resource resource1 = new Resource("resource1");
Resource resource2 = new Resource("resource2");
try (Resource r1 = resource1; Resource r2 = resource2) {
}
final Resource resource1 = new Resource("resource1");
Resource resource2 = new Resource("resource2");
try (resource1; resource2) {
} public class TryDemo { public static void main(String[] args) throws IOException {
final FileReader fr = new FileReader("in.txt"); FileWriter fw = new FileWriter("out.txt");
try (fr; fw) {
int b;
while ((b = fr.read())!=‐1) {
fw.write(b); } } catch (IOException e) { e.printStackTrace(); } } }
|