Java Utililty Methods Scanner Read All

List of utility methods to do Scanner Read All

Description

The list of methods to do Scanner Read All are organized into topic(s).

Method

StringreadTextFile(File file)
read Text File
return readString(new FileInputStream(file));
StringreadTextFile(File file)
read Text File
try {
    return readText(new FileInputStream(file));
} catch (Exception e) {
    throw new RuntimeException("Reading text file \"" + file + "\" failed", e);
StringreadTextFile(String filename)
read Text File
return readTextFile(new File(filename));
StringreadTextFile(String path)
read Text File
StringBuilder result = new StringBuilder("");
File file = new File(path);
try (Scanner scanner = new Scanner(file)) {
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        result.append(line).append(System.lineSeparator());
    scanner.close();
...
ListreadTextFile(String path)
Read the text file by one whole line and add each line to a String list.
List<String> wordList = new ArrayList<String>();
Scanner input = null;
try {
    input = new Scanner(new FileInputStream(new File(path)), "UTF-8");
    while (input.hasNext()) {
        String text = input.nextLine().trim();
        if (text.startsWith("#")) 
            continue;
...
StringreadTextFileAsString(File textFile)
Read the entire given file and return the contents as one long String.
StringBuilder outputText = new StringBuilder();
Scanner scanner = new Scanner(textFile);
while (scanner.hasNextLine()) {
    outputText.append(scanner.nextLine()).append(String.format("%n"));
scanner.close();
String actualText = outputText.toString();
return actualText;
...