![]() |
Retrieve numerical values from a text file
1 Attachment(s)
I have to retrieve numbers from a text file which is as shown in the attachment. I have written the following code snippet just to check if I am able to print the numbers in the file.
Code:
try {Code:
Exception in thread "main" java.util.InputMismatchException |
You're getting this exception because you're trying to get an int (with nextInt()) when the next token is not recognised as an integer. Have a look at the docs for Scanner here. In particular, hasNextInt() will let you see if the next token is an int and next() will let you skip any non-int input. Exactly how you want to do that depends on how strict/forgiving you want to be on the format of the configuration file.
|
| All times are GMT -5. The time now is 12:57 AM. |