public void loadFromFile(String filename) {
File file = new File(filename);
BufferedReader br;
try {
br = new BufferedReader(new FileReader(file));
numberOfAttributes = Integer.parseInt(br.readLine());
}
...
}
Above is my program: I am trying to read from a txt file where the first line is the number 22 and nothing more. I don't know why the program gives me an exception.
Try stripping any whitespace from the string:
numberOfAttributes = Integer.parseInt(br.readLine().trim());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With