Here you can find the source of readLinesNoComments(String fileName)
public static List<String> readLinesNoComments(String fileName) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public final static String UTF8 = "UTF-8"; public static List<String> readLinesNoComments(String fileName) throws IOException { return readLinesNoComments(fileName, null); }//w w w .j av a2 s .c o m public static List<String> readLinesNoComments(String fileName, String encoding) throws IOException { List<String> lines = new ArrayList<>(); try (Scanner scanner = openScanner(fileName, encoding)) { while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); if (line.length() > 0) { if (line.startsWith("#") == false) { lines.add(line); } } } } return lines; } public static final Scanner openScanner(File file) throws IOException { return openScanner(file, null); } public static final Scanner openScanner(String fileName) throws IOException { return openScanner(new File(fileName), null); } public static final Scanner openScanner(String fileName, String encoding) throws IOException { return openScanner(new File(fileName), encoding); } public static final Scanner openScanner(File file, String encoding) throws IOException { if (encoding == null) { encoding = UTF8; } FileInputStream fis = new FileInputStream(file); return new Scanner(fis, encoding); } }