I am trying to read a file into and array but it does not seem to working here is my code
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("Sales.txt"));
int lineCount = 0;
String line = "";
while (input.hasNextLine()) {
line = input.nextLine(); // read one line
lineCount++; //count line to find out how big array must be
// System.out.println(line);
}
String[] fileinput = new String[lineCount]; //create array to store file in
while (input.hasNextLine()) {
int i = 0;
fileinput[i] = input.nextLine();
System.out.println(fileinput[i]);
i++;
}
I am using the first part to find out how many lines so I can specify my array to be that size then trying to put each line into the array in my second part.
But it keeps coming back as null each time it does not seem to want to read or work with the file a second time after it works with it the first time.
Any help would be greatly appreciated.
Thanks