Java BufferedReader Read readFile(String fileName, String commentFlag)

Here you can find the source of readFile(String fileName, String commentFlag)

Description

Copied from Util.java

License

Open Source License

Parameter

Parameter Description
fileName a parameter
commentFlag a parameter

Declaration

private static StringBuffer readFile(String fileName, String commentFlag) 

Method Source Code

//package com.java2s;
/**//from  w  w w.ja  va 2 s .  c  o  m
* A Stanford CoreNLP tree visualizer. 
* Copyright (C) 2014  Long Qiu
    
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
    
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
    
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Main {
    /**
     * Copied from Util.java
     * @param fileName
     * @param commentFlag
     * @return
     */
    private static StringBuffer readFile(String fileName, String commentFlag) {
        StringBuffer sb = new StringBuffer();
        try {
            BufferedReader in = new BufferedReader(new FileReader(fileName));
            String s;
            while ((s = in.readLine()) != null) {
                if (commentFlag != null && s.trim().startsWith(commentFlag)) {
                    //ignore this line
                    continue;
                }
                sb.append(s);
                //sb.append("/n"); to make it more platform independent (Log July 12, 2004)
                sb.append(System.getProperty("line.separator"));
            }
            in.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return sb;
    }
}

Related

  1. readFile(String fileName)
  2. readFile(String filename, boolean print)
  3. readFile(String filename, boolean skipEmptyLine)
  4. readFile(String fileName, String basePath)
  5. readFile(String fileName, String commentFlag)
  6. readFile(String fileNm)
  7. readFile(String filePath)
  8. readFile(String filePath)
  9. readFile(String filePath)