Java Scanner Read readFile(String pathname)

Here you can find the source of readFile(String pathname)

Description

This method reads a file and returns the file content as char array.

License

Open Source License

Parameter

Parameter Description
pathname a parameter

Exception

Parameter Description
FileNotFoundException an exception

Declaration

public static char[] readFile(String pathname) throws FileNotFoundException 

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 {
    /**/* w  w w .  j  a  v a 2 s  .co m*/
     * This method reads a file and returns the file content as char array.
     * Furthermore the method do not read the line termination char '\n'.
     * 
     * @param pathname
     * @return
     * @throws FileNotFoundException 
     */
    public static char[] readFile(String pathname) throws FileNotFoundException {
        File file = new File(pathname);
        String str = "";
        Scanner scanner = new Scanner(file);
        while (scanner.hasNextLine()) {
            str += scanner.nextLine();
        }
        return str.toLowerCase().toCharArray();
    }
}

Related

  1. readFile(String fileName)
  2. readFile(String filePath)
  3. readFile(String filePath)
  4. readFile(String filePath)
  5. readFile(String path)
  6. readFile(String project, boolean judge)
  7. readFileFully(InputStream stream)
  8. readFileToList(File file)
  9. readFileWithoutComments(File input)