Search code examples
javabigintegernumberformatexception

Java BigInteger & String


I have this code which reads an encrypted piece of a string (so, some garbage value when opened using notepad) but I keep getting "java.lang.NumberFormatException: Illegal embedded sign character".

FileReader fr = new FileReader("encrypted.txt"); 
Scanner sc = new Scanner(fr);
String s = sc.nextLine();

BigInteger OC = new BigInteger(s);

I wonder if it has something to do with the version of SDK I'm using to compile which keep giving me errors, or just mistake somewhere in the code.


Solution

  • encrypted.txt file should have numbers and not encoded strings. If you change it, it will work. The reason is BigInteger() constructor expects a string which has only numbers.