Here you can find the source of listOfWords(String filePath)
Parameter | Description |
---|---|
filePath | relative/absolute filePath on disk |
Parameter | Description |
---|---|
FileNotFoundException | if file is not found on disk |
public static Set<String> listOfWords(String filePath) throws FileNotFoundException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileNotFoundException; import java.nio.file.Paths; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { private static Set<String> words = new HashSet<>(); /**//from w ww . j a v a 2s . c om * Reads the file from the given path * @param filePath relative/absolute filePath on disk * @return Set of all the words in the file * @throws FileNotFoundException if file is not found on disk */ public static Set<String> listOfWords(String filePath) throws FileNotFoundException { String path = Paths.get(".").toAbsolutePath().normalize().toString(); try (Scanner scanner = new Scanner(new File(path + "/" + filePath))) { while (scanner.hasNext()) { words.add(scanner.nextLine()); } return words; } } }