How do I add a line from a file into an array? [on hold]
I have a file that looks like this:
17 12 15
7 54 9873 1867 4425 878 365 783
4
20
I am trying to get each line into it's own array so it would be something
like this:
array1[] = {17, 12, 15}
array2[] = {7, 54, 9873, 1867, 4425, 878, 365, 783}
array3[] = {4}
array4[] = {20}
This is what my code looks like so far:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class FunTime {
public static void main(String[] args) throws IOException{
try (BufferedReader br = new BufferedReader(new
FileReader("funtime.txt"))){
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
System.out.println(sCurrentLine);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
I can read the file and it prints it out line by line but I don't know how
to add each line into an array. Any ideas?
No comments:
Post a Comment