Java Reader Read Line readLinesTrimmedNoCommmentFromBufferedReader(final BufferedReader in, final String commentString)

Here you can find the source of readLinesTrimmedNoCommmentFromBufferedReader(final BufferedReader in, final String commentString)

Description

read Lines Trimmed No Commment From Buffered Reader

License

Apache License

Declaration

private static String[] readLinesTrimmedNoCommmentFromBufferedReader(final BufferedReader in,
            final String commentString) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;

import java.io.IOException;

import java.util.ArrayList;

public class Main {
    private static String[] readLinesTrimmedNoCommmentFromBufferedReader(final BufferedReader in,
            final String commentString) throws IOException {
        ArrayList<String> lineList = new ArrayList<String>();
        String line;/*w w  w  .  j  a  v  a  2  s . co  m*/
        while (in.ready()) {
            line = in.readLine();
            if (line == null) {
                continue;
            }

            line = line.trim();

            if (line.startsWith(commentString))
                continue;

            if (line.contains(commentString)) {
                String[] items = line.split(commentString);
                line = items[0].trim();
            }

            lineList.add(line);
        }

        in.close();

        String[] lines = new String[lineList.size()];

        lineList.toArray(lines);

        return lines;
    }
}

Related

  1. readLines(Reader reader)
  2. readLines(Reader reader)
  3. readLines(Reader reader)
  4. readLinesFromReader(final Reader reader)
  5. readLinesToList(BufferedReader bufferedReader)
  6. readLinesWithContinuation(BufferedReader rdr, StringBuilder sb, int maxSize)