Java array and string question
I have a list of test which I want to place into an array. How would I take text from a file, line by line, and then place each line into its own array element? Something like this:
Bob Hall
Cliff Jackson
Casey Waters
myArray[0] = Bob Hall, myArray[1] = Cliff Jackson, myArray[2] = Casey Waters
Re: Java array and string question
You'd have to set up a buffered reader then have it collect the data from the file in the line-by-line manner you're wanting and have it in a for loop that counts and just have i as the place in the array and have the line assigned to that place in the array
Re: Java array and string question
Quote:
Originally Posted by
colerelm
I have a list of test which I want to place into an array. How would I take text from a file, line by line, and then place each line into its own array element? Something like this:
Bob Hall
Cliff Jackson
Casey Waters
myArray[0] = Bob Hall, myArray[1] = Cliff Jackson, myArray[2] = Casey Waters
Use readLine() of a BufferedReader. It reads until a CR or LF character.