Here you can find the source of readFile(String pathname)
Parameter | Description |
---|---|
pathname | a parameter |
Parameter | Description |
---|---|
FileNotFoundException | an exception |
public static char[] readFile(String pathname) throws FileNotFoundException
//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(); } }