Hi i want to read words form a text file placed in the same folder as the java file and then hold the information in an array.
so far ive written code to read the text file (i think) im trying to teach my self so if ive done this bit wrong please tell me.
public static void main(String[] args)
{
String testText = IO.readString ("testText.txt");
try
{
FileReader reader = new FileReader(testText);
Scanner in = new Scanner(reader);
out.close();
}//try
catch IOException
{
System.out.println("Error processing file:"
+ exception);
}
}//main
But now i need to hold the words in an array. I was thinking something along the lines of.......
private String[] wordList;
wordList = new String [50];
private void readTestText()
{
String currentWord = scanner.next();
int i = 0;
while (currentWord != null)
{
wordList = currentWord;
currentWord = scanner.next();
i++;
}
What do you think that the right idea and would it work?