ReadLines: read file to list of strings : Text File « File « Java Tutorial






import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

public class Utils {

  public static List<String> readLines(File file) throws Exception {
      if (!file.exists()) {
          return new ArrayList<String>();
      }
      BufferedReader reader = new BufferedReader(new FileReader(file));
      List<String> results = new ArrayList<String>();
      String line = reader.readLine();
      while (line != null) {
          results.add(line);
          line = reader.readLine();
      }
      return results;
  }
}








11.80.Text File
11.80.1.Read the contents of a file and place them in a string object.
11.80.2.Dump a String to a text file with encoding.
11.80.3.Load a text file contents as a String.
11.80.4.Read and return the entire contents of the supplied File.
11.80.5.Read ByteArrayInputStream to String
11.80.6.Load File As Text
11.80.7.Load file line by line
11.80.8.Load file content to List
11.80.9.Read string from InputStream and Reader
11.80.10.Gets the content from a File as String Array List
11.80.11.Searches case sensitively in a file
11.80.12.ReadLines: read file to list of strings