Java Scanner Read readFileFully(InputStream stream)

Here you can find the source of readFileFully(InputStream stream)

Description

read File Fully

License

Open Source License

Declaration

public static String readFileFully(InputStream stream) throws IOException 

Method Source Code

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

import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;

public class Main {
    public static String readFileFully(InputStream stream) throws IOException {
        StringBuilder stringBuilder = new StringBuilder();

        try (Scanner scanner = new Scanner(stream)) {
            while (scanner.hasNext()) {
                stringBuilder.append(scanner.next());
            }//from   w w  w  .java  2  s  .  com
        }

        return stringBuilder.toString();
    }

    public static String toString(java.io.InputStream is) {
        try (Scanner scanner = new java.util.Scanner(is).useDelimiter("\\A")) {
            return scanner.hasNext() ? scanner.next() : "";
        }
    }
}

Related

  1. readFile(String filePath)
  2. readFile(String filePath)
  3. readFile(String path)
  4. readFile(String pathname)
  5. readFile(String project, boolean judge)
  6. readFileToList(File file)
  7. readFileWithoutComments(File input)
  8. readFromReader(Scanner scanner)
  9. readFromScanner(Scanner scanner)