Java Text File Read All readAll(File file)

Here you can find the source of readAll(File file)

Description

read All

License

Apache License

Declaration

public static String readAll(File file) throws FileNotFoundException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

import java.util.Scanner;

public class Main {
    public static String readAll(File file) throws FileNotFoundException {
        StringBuilder builder = new StringBuilder();
        FileInputStream intput = new FileInputStream(file);
        Scanner scanner = new Scanner(intput, "UTF-8");
        while (scanner.hasNextLine()) {
            builder.append(scanner.nextLine());
            builder.append("\n");
        }/*w w w  .jav a2  s.c  o m*/
        scanner.close();
        return builder.toString();
    }
}

Related

  1. readAll(File file)
  2. readAll(final String path)
  3. readAllFile(File file)
  4. readAllFile(String fileName)
  5. readAllText(final String filename)