Java Scanner Read readFile(File file)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(File file) 

Method Source Code

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

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

import java.util.Scanner;

public class Main {
    public static String readFile(File file) {
        Scanner scan;// w ww  . j  a va2s  .  c  om
        try {
            scan = new Scanner(file);
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
            return null;
        }
        String content = scan.useDelimiter("\\Z").next();
        content = content.replaceAll("\\r", "");
        scan.close();
        return content;
    }
}

Related

  1. readFile(File file)
  2. readFile(File file)
  3. readFile(File file)
  4. readFile(File file)
  5. readFile(File file)
  6. readFile(File input)
  7. readFile(File path)
  8. readFile(final File f)
  9. readFile(String file_name)