Java Scanner Read readFileWithoutComments(File input)

Here you can find the source of readFileWithoutComments(File input)

Description

read File Without Comments

License

Open Source License

Declaration

public static Set<String> readFileWithoutComments(File input) throws FileNotFoundException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileNotFoundException;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static Set<String> readFileWithoutComments(File input) throws FileNotFoundException {
        Set<String> adsList;

        try (Scanner scanner = new Scanner(input)) {
            adsList = new HashSet<String>(10000);
            final String COMMENT_MARKER = "#";
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine().trim();
                if (line.startsWith(COMMENT_MARKER) || line.isEmpty()) {
                    continue;
                }/*from   ww w.  j  av  a2s . co  m*/
                line = line.replaceAll(COMMENT_MARKER + ".*$", "");
                adsList.add(line);
            }
        }
        return adsList;
    }
}

Related

  1. readFile(String path)
  2. readFile(String pathname)
  3. readFile(String project, boolean judge)
  4. readFileFully(InputStream stream)
  5. readFileToList(File file)
  6. readFromReader(Scanner scanner)
  7. readFromScanner(Scanner scanner)
  8. readInt(String prompt)
  9. readLine(String format, Object... args)