mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
extract field from auto closable (IDEA-125141)
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
class JavaClass {
|
||||
|
||||
static String readFirstLineFromFile() throws IOException {
|
||||
try (BufferedReader br = createReader("any")) {
|
||||
return b<caret>r.readLine();
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedReader createReader(String path) {
|
||||
try {
|
||||
return new BufferedReader(new FileReader(path));
|
||||
} catch (FileNotFoundException e) {
|
||||
// for example purposes #createReader shouldn't throw any checked exception
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
class JavaClass {
|
||||
|
||||
private static BufferedReader br;
|
||||
|
||||
static String readFirstLineFromFile() throws IOException {
|
||||
try (br = createReader("any")) {
|
||||
return br.readLine();
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedReader createReader(String path) {
|
||||
try {
|
||||
return new BufferedReader(new FileReader(path));
|
||||
} catch (FileNotFoundException e) {
|
||||
// for example purposes #createReader shouldn't throw any checked exception
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user