Java Utililty Methods Text File Read Line

List of utility methods to do Text File Read Line

Description

The list of methods to do Text File Read Line are organized into topic(s).

Method

StringreadLines(final File file)
read Lines
final InputStream stream = new FileInputStream(file);
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String lines = "";
String line;
while ((line = reader.readLine()) != null)
    lines += line;
reader.close();
stream.close();
...
String[]readlines(final File file)
readlines
final BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line = null;
final List<String> allLines = new ArrayList<String>();
while ((line = br.readLine()) != null) {
    allLines.add(line);
br.close();
return allLines.toArray(new String[allLines.size()]);
...
ListreadLines(int problemNumber)
read Lines
String fileName = "src/com/sangupta/maer/dataFiles/problem" + String.valueOf(problemNumber) + ".txt";
return readLines(fileName);
ListreadLines(String body)
read Lines
final BufferedReader reader = new BufferedReader(new StringReader(body));
final List<String> lines = new ArrayList<String>();
try {
    for (String line = reader.readLine(); line != null; line = reader.readLine()) {
        line = line.trim();
        if (line.length() > 1) {
            lines.add(line);
} catch (IOException ignored) {
return lines;
VectorreadLines(String file)
Read all lines of text in a file.
Vector contents = new Vector();
BufferedReader in = new BufferedReader(new FileReader(file));
while (true) {
    String line = in.readLine();
    if (line == null) {
        break;
    } else {
        contents.addElement(line);
...
ListreadLines(String file)
read Lines
BufferedReader reader = null;
List<String> lines;
String line;
lines = new ArrayList<String>();
try {
    reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
    while ((line = reader.readLine()) != null)
        lines.add(line);
...
voidreadLines(String file, ArrayList lines)
read Lines
BufferedReader reader = null;
try {
    reader = new BufferedReader(new FileReader(new File(file)));
    String line = null;
    while ((line = reader.readLine()) != null) {
        lines.add(line);
} catch (FileNotFoundException e) {
...
ListreadLines(String filename)
read Lines
BufferedReader br = new BufferedReader(new FileReader(filename));
ArrayList<String> res = new ArrayList<String>();
while (br.ready()) {
    res.add(br.readLine());
br.close();
return res;
ListreadLines(String fileName)
read Lines
File file = new File(fileName);
return readLines(file);
Iterablereadlines(String filename)
readlines
final FileReader fr = new FileReader(filename);
final BufferedReader br = new BufferedReader(fr);
return new Iterable<String>() {
    public Iterator<String> iterator() {
        return new Iterator<String>() {
            public boolean hasNext() {
                return line != null;
            public String next() {
                String retval = line;
                line = getLine();
                return retval;
            public void remove() {
                throw new UnsupportedOperationException();
            String getLine() {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException ioEx) {
                    line = null;
                return line;
            String line = getLine();
        };
};