3 ms·
Java 7 has a implementation pattern built in for this now: String readFirstLineFromFile(String path) throws IOException { try (BufferedReader br = new Buffer
by spullara 15y ago
Java 7 has a implementation pattern built in for this now:
String readFirstLineFromFile(String path) throws IOException {
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
return br.readLine();
}
}
Anything that implements the AutoCloseable interface gets this behavior for free.