MCPcopy
hub / github.com/google/guava / readLines

Method readLines

android/guava/src/com/google/common/io/Files.java:543–562  ·  view source on GitHub ↗

Reads all of the lines from a file. The lines do not include line-termination characters, but do include other leading and trailing whitespace. <p>This method returns a mutable {@code List}. For an {@code ImmutableList}, use {@code Files.asCharSource(file, charset).readLines()}. <p><b>{@link java.

(File file, Charset charset)

Source from the content-addressed store, hash-verified

541 * @throws IOException if an I/O error occurs
542 */
543 public static List<String> readLines(File file, Charset charset) throws IOException {
544 // don't use asCharSource(file, charset).readLines() because that returns
545 // an immutable list, which would change the behavior of this method
546 return asCharSource(file, charset)
547 .readLines(
548 new LineProcessor<List<String>>() {
549 final List<String> result = new ArrayList<>();
550
551 @Override
552 public boolean processLine(String line) {
553 result.add(line);
554 return true;
555 }
556
557 @Override
558 public List<String> getResult() {
559 return result;
560 }
561 });
562 }
563
564 /**
565 * Streams lines from a {@link File}, stopping when our callback returns false, or we have read

Calls 1

asCharSourceMethod · 0.95