-1

How can I read from a text file and stores the values into a an array list I specified, I have the following code so far

FileReader file = new FileReader("C:\\");
        BufferedReader reader = new BufferedReader(file);

        String text = "";
        String line = reader.readLine();
        while (line != null){

            text += line;
            line = reader.readLine();
        }
        System.out.println(text);

I want to limit the lines to 6 any line over that should provide an arrow, and I also want to check whether the values given by the user is appropriate. The array list I have created is called arraysList.

The user can enter upto 6 lines, in format, String, double, int, int

The error check I want is say if the integers the user enters is below 0 or above 100 it should provide an error and if the double is below 0 it should provide an error and also if the String does not match

Apple || Banana || Orange || PineApple || Grape || Mango

I want to store each line in the array list, but separate the values so after every space in line, and so on...

Thanks.

1 Answers1

1

This line is your problem.

FileReader file = new FileReader("C:\\");

It should be something like

FileReader file = new FileReader("C:\\input.txt");

Point the reader to your actual file, I mean.

peter.petrov
  • 38,363
  • 16
  • 94
  • 159