I have a text file of full of sentences and I am trying to get the individual words split up into a two dimensional array in java. The rows of the array correspond to the lines of the text, and the columns are the individual words. Any help would be much appreciated.
You just need a few things:
BufferedReader, which has the method
public String readLine()to read a line from the file.
- the method
public String split(String regex)from
Stringclass that can split a string with specified regular expression and already place single strings in an array.
- iterate over the file, read a line as long as there are available, split the line, and store all of them in a list
- convert the list to an array and you are done