BufferedReader.lines java
|
|
Среда, 05 Февраля 2014 г. 09:14
+ в цитатник
public static void main(String[] args) {
try (BufferedReader reader = Files.newBufferedReader(
Paths.get("myfile.txt"),
StandardCharsets.UTF_8)) {
System.out.println(reader.lines().count());
} catch (IOException ex) {
}
}
Print out all the lines:
public static void main(String[] args) {
try (BufferedReader reader = Files.newBufferedReader(
Paths.get("myfile.txt"),
StandardCharsets.UTF_8)) {
reader.lines().forEach(System.out::println);
} catch (IOException ex) {
}
}
Print out the longest line in a file:
public static void main(String[] args) {
try (BufferedReader reader = Files.newBufferedReader(
Paths.get("myfile.txt"),
StandardCharsets.UTF_8)) {
System.out.println(reader
.lines()
.mapToInt(String::length)
.max()
.getAsInt());
} catch (IOException ex) {
}
}
Метки:
BufferedReader.lines
BufferedReader
java
-
Запись понравилась
-
0
Процитировали
-
0
Сохранили
-