Here you can find the source of fileToStringArray(String fileName)
public static String[] fileToStringArray(String fileName) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static String[] fileToStringArray(String fileName) throws IOException { String data = fileToString(fileName); String str = cleanText(data); String[] wordArray = str.split(" "); return wordArray; }/*w ww . java2 s .c om*/ public static String fileToString(String fileName) throws IOException { String result = ""; try { FileInputStream file = new FileInputStream(fileName); byte[] b = new byte[file.available()]; file.read(b); file.close(); result = new String(b); } catch (FileNotFoundException e) { System.out.println("oops"); } return result; } public static String cleanText(String s) { s = s.replaceAll("\\p{Punct}", ""); s = s.replaceAll("\\s+", " "); return s; } }