Here you can find the source of getNextLine(final Scanner source)
Parameter | Description |
---|---|
source | The scanner to read lines from. |
static String getNextLine(final Scanner source)
//package com.java2s; /*//from w w w. j a v a2 s . com * Geotoolkit - An Open Source Java GIS Toolkit * http://www.geotoolkit.org * * (C) 2010-2015, Geomatys * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library 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 * Lesser General Public License for more details. */ import java.util.Scanner; public class Main { public static final String COMMENT_STRING = "#"; /** * Read lines from input {@link java.util.Scanner} until it finds a non-commented line, then send it back. * @param source The scanner to read lines from. * @return The first non-commented line found, or null if scanner is empty or contains only comments. */ static String getNextLine(final Scanner source) { String line; while (source.hasNextLine()) { line = source.nextLine(); if (line.startsWith(COMMENT_STRING)) { continue; } else { final int commentIndex = line.indexOf(COMMENT_STRING); if (commentIndex < 0) { return line; } else { return line.substring(0, commentIndex); } } } return null; } }