Java-Scanner not working with nextByte()
java
Solution
`java.util.Scanner` is intended for scanning text.
So when you call `Scanner#nextByte()`, what it really expects to find is a textual representation of a number. For example, if you had "98" there instead of "b", it would have read 98 into that byte variable.
Problem
``` Scanner Sc = new Scanner(new File("Input.bin")); String s = Sc.nextLine(); fsize = Integer.parseInt(s); // Reads 4 s = Sc.nextLine(); int mapSize = Integer.parseInt(s); // Reads 3 for (int i = 0; i < mapSize; i++) { byte value = 0; value = Sc.nextByte(); // Here it is throwing the exception it should have // print the ascii of 'b' which is 98???? String key = Sc.nextLine(); key = key.trim(); dcMap.put(key, (char)value); // System.out.println(key + " " + (char)value); } ``` Input.bin file contents: ``` 4 3 b 0 c 10 a 11 ```